hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 11 | #import "RTCPeerConnection+Private.h" |
| 12 | |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 13 | #import "RTCConfiguration+Private.h" |
| 14 | #import "RTCDataChannel+Private.h" |
| 15 | #import "RTCIceCandidate+Private.h" |
hbos | bd3dda6 | 2016-09-09 01:36:28 -0700 | [diff] [blame] | 16 | #import "RTCLegacyStatsReport+Private.h" |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 17 | #import "RTCMediaConstraints+Private.h" |
| 18 | #import "RTCMediaStream+Private.h" |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 19 | #import "RTCMediaStreamTrack+Private.h" |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 20 | #import "RTCPeerConnectionFactory+Private.h" |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 21 | #import "RTCRtpReceiver+Private.h" |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 22 | #import "RTCRtpSender+Private.h" |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 23 | #import "RTCRtpTransceiver+Private.h" |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 24 | #import "RTCSessionDescription+Private.h" |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame] | 25 | #import "base/RTCLogging.h" |
| 26 | #import "helpers/NSString+StdString.h" |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 27 | |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 28 | #include <memory> |
| 29 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 30 | #include "api/jsep_ice_candidate.h" |
Niels Möller | 695cf6a | 2019-05-13 12:27:23 +0200 | [diff] [blame] | 31 | #include "api/rtc_event_log_output_file.h" |
Niels Möller | 65f17ca | 2019-09-12 13:59:36 +0200 | [diff] [blame] | 32 | #include "api/transport/media/media_transport_interface.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 33 | #include "rtc_base/checks.h" |
Niels Möller | 695cf6a | 2019-05-13 12:27:23 +0200 | [diff] [blame] | 34 | #include "rtc_base/numerics/safe_conversions.h" |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 35 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 36 | NSString *const kRTCPeerConnectionErrorDomain = @"org.webrtc.RTC_OBJC_TYPE(RTCPeerConnection)"; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 37 | int const kRTCPeerConnnectionSessionDescriptionError = -1; |
| 38 | |
| 39 | namespace webrtc { |
| 40 | |
| 41 | class CreateSessionDescriptionObserverAdapter |
| 42 | : public CreateSessionDescriptionObserver { |
| 43 | public: |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 44 | CreateSessionDescriptionObserverAdapter(void (^completionHandler)( |
| 45 | RTC_OBJC_TYPE(RTCSessionDescription) * sessionDescription, NSError *error)) { |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 46 | completion_handler_ = completionHandler; |
| 47 | } |
| 48 | |
Mirko Bonadei | 17aff35 | 2018-07-26 12:20:40 +0200 | [diff] [blame] | 49 | ~CreateSessionDescriptionObserverAdapter() override { completion_handler_ = nil; } |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 50 | |
| 51 | void OnSuccess(SessionDescriptionInterface *desc) override { |
| 52 | RTC_DCHECK(completion_handler_); |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 53 | std::unique_ptr<webrtc::SessionDescriptionInterface> description = |
| 54 | std::unique_ptr<webrtc::SessionDescriptionInterface>(desc); |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 55 | RTC_OBJC_TYPE(RTCSessionDescription) *session = |
| 56 | [[RTC_OBJC_TYPE(RTCSessionDescription) alloc] initWithNativeDescription:description.get()]; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 57 | completion_handler_(session, nil); |
| 58 | completion_handler_ = nil; |
| 59 | } |
| 60 | |
Harald Alvestrand | 73771a8 | 2018-05-24 10:53:49 +0200 | [diff] [blame] | 61 | void OnFailure(RTCError error) override { |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 62 | RTC_DCHECK(completion_handler_); |
Harald Alvestrand | 73771a8 | 2018-05-24 10:53:49 +0200 | [diff] [blame] | 63 | // TODO(hta): Add handling of error.type() |
| 64 | NSString *str = [NSString stringForStdString:error.message()]; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 65 | NSError* err = |
| 66 | [NSError errorWithDomain:kRTCPeerConnectionErrorDomain |
| 67 | code:kRTCPeerConnnectionSessionDescriptionError |
| 68 | userInfo:@{ NSLocalizedDescriptionKey : str }]; |
| 69 | completion_handler_(nil, err); |
| 70 | completion_handler_ = nil; |
| 71 | } |
| 72 | |
| 73 | private: |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 74 | void (^completion_handler_)(RTC_OBJC_TYPE(RTCSessionDescription) * sessionDescription, |
| 75 | NSError *error); |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | class SetSessionDescriptionObserverAdapter : |
| 79 | public SetSessionDescriptionObserver { |
| 80 | public: |
| 81 | SetSessionDescriptionObserverAdapter(void (^completionHandler) |
| 82 | (NSError *error)) { |
| 83 | completion_handler_ = completionHandler; |
| 84 | } |
| 85 | |
Mirko Bonadei | 17aff35 | 2018-07-26 12:20:40 +0200 | [diff] [blame] | 86 | ~SetSessionDescriptionObserverAdapter() override { completion_handler_ = nil; } |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 87 | |
| 88 | void OnSuccess() override { |
| 89 | RTC_DCHECK(completion_handler_); |
| 90 | completion_handler_(nil); |
| 91 | completion_handler_ = nil; |
| 92 | } |
| 93 | |
Harald Alvestrand | 73771a8 | 2018-05-24 10:53:49 +0200 | [diff] [blame] | 94 | void OnFailure(RTCError error) override { |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 95 | RTC_DCHECK(completion_handler_); |
Harald Alvestrand | 73771a8 | 2018-05-24 10:53:49 +0200 | [diff] [blame] | 96 | // TODO(hta): Add handling of error.type() |
| 97 | NSString *str = [NSString stringForStdString:error.message()]; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 98 | NSError* err = |
| 99 | [NSError errorWithDomain:kRTCPeerConnectionErrorDomain |
| 100 | code:kRTCPeerConnnectionSessionDescriptionError |
| 101 | userInfo:@{ NSLocalizedDescriptionKey : str }]; |
| 102 | completion_handler_(err); |
| 103 | completion_handler_ = nil; |
| 104 | } |
| 105 | |
| 106 | private: |
| 107 | void (^completion_handler_)(NSError *error); |
| 108 | }; |
| 109 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 110 | PeerConnectionDelegateAdapter::PeerConnectionDelegateAdapter(RTC_OBJC_TYPE(RTCPeerConnection) * |
| 111 | peerConnection) { |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 112 | peer_connection_ = peerConnection; |
| 113 | } |
| 114 | |
| 115 | PeerConnectionDelegateAdapter::~PeerConnectionDelegateAdapter() { |
| 116 | peer_connection_ = nil; |
| 117 | } |
| 118 | |
| 119 | void PeerConnectionDelegateAdapter::OnSignalingChange( |
| 120 | PeerConnectionInterface::SignalingState new_state) { |
| 121 | RTCSignalingState state = |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 122 | [[RTC_OBJC_TYPE(RTCPeerConnection) class] signalingStateForNativeState:new_state]; |
| 123 | RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 124 | [peer_connection.delegate peerConnection:peer_connection |
| 125 | didChangeSignalingState:state]; |
| 126 | } |
| 127 | |
| 128 | void PeerConnectionDelegateAdapter::OnAddStream( |
deadbeef | d5f41ce | 2016-06-08 13:31:45 -0700 | [diff] [blame] | 129 | rtc::scoped_refptr<MediaStreamInterface> stream) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 130 | RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; |
| 131 | RTC_OBJC_TYPE(RTCMediaStream) *mediaStream = |
| 132 | [[RTC_OBJC_TYPE(RTCMediaStream) alloc] initWithFactory:peer_connection.factory |
| 133 | nativeMediaStream:stream]; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 134 | [peer_connection.delegate peerConnection:peer_connection |
| 135 | didAddStream:mediaStream]; |
| 136 | } |
| 137 | |
| 138 | void PeerConnectionDelegateAdapter::OnRemoveStream( |
deadbeef | d5f41ce | 2016-06-08 13:31:45 -0700 | [diff] [blame] | 139 | rtc::scoped_refptr<MediaStreamInterface> stream) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 140 | RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; |
| 141 | RTC_OBJC_TYPE(RTCMediaStream) *mediaStream = |
| 142 | [[RTC_OBJC_TYPE(RTCMediaStream) alloc] initWithFactory:peer_connection.factory |
| 143 | nativeMediaStream:stream]; |
Yura Yaroshevich | c806c1d | 2018-06-21 12:51:11 +0300 | [diff] [blame] | 144 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 145 | [peer_connection.delegate peerConnection:peer_connection |
| 146 | didRemoveStream:mediaStream]; |
| 147 | } |
| 148 | |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 149 | void PeerConnectionDelegateAdapter::OnTrack( |
| 150 | rtc::scoped_refptr<RtpTransceiverInterface> nativeTransceiver) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 151 | RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; |
| 152 | RTC_OBJC_TYPE(RTCRtpTransceiver) *transceiver = |
| 153 | [[RTC_OBJC_TYPE(RTCRtpTransceiver) alloc] initWithFactory:peer_connection.factory |
| 154 | nativeRtpTransceiver:nativeTransceiver]; |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 155 | if ([peer_connection.delegate |
| 156 | respondsToSelector:@selector(peerConnection:didStartReceivingOnTransceiver:)]) { |
| 157 | [peer_connection.delegate peerConnection:peer_connection |
| 158 | didStartReceivingOnTransceiver:transceiver]; |
| 159 | } |
| 160 | } |
| 161 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 162 | void PeerConnectionDelegateAdapter::OnDataChannel( |
deadbeef | d5f41ce | 2016-06-08 13:31:45 -0700 | [diff] [blame] | 163 | rtc::scoped_refptr<DataChannelInterface> data_channel) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 164 | RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; |
| 165 | RTC_OBJC_TYPE(RTCDataChannel) *dataChannel = |
| 166 | [[RTC_OBJC_TYPE(RTCDataChannel) alloc] initWithFactory:peer_connection.factory |
| 167 | nativeDataChannel:data_channel]; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 168 | [peer_connection.delegate peerConnection:peer_connection |
| 169 | didOpenDataChannel:dataChannel]; |
| 170 | } |
| 171 | |
| 172 | void PeerConnectionDelegateAdapter::OnRenegotiationNeeded() { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 173 | RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 174 | [peer_connection.delegate peerConnectionShouldNegotiate:peer_connection]; |
| 175 | } |
| 176 | |
| 177 | void PeerConnectionDelegateAdapter::OnIceConnectionChange( |
| 178 | PeerConnectionInterface::IceConnectionState new_state) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 179 | RTCIceConnectionState state = |
| 180 | [RTC_OBJC_TYPE(RTCPeerConnection) iceConnectionStateForNativeState:new_state]; |
Jonas Olsson | cfddbb7 | 2018-11-15 16:52:45 +0100 | [diff] [blame] | 181 | [peer_connection_.delegate peerConnection:peer_connection_ didChangeIceConnectionState:state]; |
| 182 | } |
| 183 | |
Qingsi Wang | 36e3147 | 2019-05-29 11:37:26 -0700 | [diff] [blame] | 184 | void PeerConnectionDelegateAdapter::OnStandardizedIceConnectionChange( |
| 185 | PeerConnectionInterface::IceConnectionState new_state) { |
| 186 | if ([peer_connection_.delegate |
| 187 | respondsToSelector:@selector(peerConnection:didChangeStandardizedIceConnectionState:)]) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 188 | RTCIceConnectionState state = |
| 189 | [RTC_OBJC_TYPE(RTCPeerConnection) iceConnectionStateForNativeState:new_state]; |
Qingsi Wang | 36e3147 | 2019-05-29 11:37:26 -0700 | [diff] [blame] | 190 | [peer_connection_.delegate peerConnection:peer_connection_ |
| 191 | didChangeStandardizedIceConnectionState:state]; |
| 192 | } |
| 193 | } |
| 194 | |
Jonas Olsson | cfddbb7 | 2018-11-15 16:52:45 +0100 | [diff] [blame] | 195 | void PeerConnectionDelegateAdapter::OnConnectionChange( |
| 196 | PeerConnectionInterface::PeerConnectionState new_state) { |
| 197 | if ([peer_connection_.delegate |
| 198 | respondsToSelector:@selector(peerConnection:didChangeConnectionState:)]) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 199 | RTCPeerConnectionState state = |
| 200 | [RTC_OBJC_TYPE(RTCPeerConnection) connectionStateForNativeState:new_state]; |
Jonas Olsson | cfddbb7 | 2018-11-15 16:52:45 +0100 | [diff] [blame] | 201 | [peer_connection_.delegate peerConnection:peer_connection_ didChangeConnectionState:state]; |
| 202 | } |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | void PeerConnectionDelegateAdapter::OnIceGatheringChange( |
| 206 | PeerConnectionInterface::IceGatheringState new_state) { |
| 207 | RTCIceGatheringState state = |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 208 | [[RTC_OBJC_TYPE(RTCPeerConnection) class] iceGatheringStateForNativeState:new_state]; |
| 209 | RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 210 | [peer_connection.delegate peerConnection:peer_connection |
| 211 | didChangeIceGatheringState:state]; |
| 212 | } |
| 213 | |
| 214 | void PeerConnectionDelegateAdapter::OnIceCandidate( |
| 215 | const IceCandidateInterface *candidate) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 216 | RTC_OBJC_TYPE(RTCIceCandidate) *iceCandidate = |
| 217 | [[RTC_OBJC_TYPE(RTCIceCandidate) alloc] initWithNativeCandidate:candidate]; |
| 218 | RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 219 | [peer_connection.delegate peerConnection:peer_connection |
| 220 | didGenerateIceCandidate:iceCandidate]; |
| 221 | } |
Honghai Zhang | da2ba4d | 2016-05-23 11:53:14 -0700 | [diff] [blame] | 222 | |
| 223 | void PeerConnectionDelegateAdapter::OnIceCandidatesRemoved( |
| 224 | const std::vector<cricket::Candidate>& candidates) { |
| 225 | NSMutableArray* ice_candidates = |
| 226 | [NSMutableArray arrayWithCapacity:candidates.size()]; |
| 227 | for (const auto& candidate : candidates) { |
| 228 | std::unique_ptr<JsepIceCandidate> candidate_wrapper( |
| 229 | new JsepIceCandidate(candidate.transport_name(), -1, candidate)); |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 230 | RTC_OBJC_TYPE(RTCIceCandidate) *ice_candidate = |
| 231 | [[RTC_OBJC_TYPE(RTCIceCandidate) alloc] initWithNativeCandidate:candidate_wrapper.get()]; |
Honghai Zhang | da2ba4d | 2016-05-23 11:53:14 -0700 | [diff] [blame] | 232 | [ice_candidates addObject:ice_candidate]; |
| 233 | } |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 234 | RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; |
Honghai Zhang | da2ba4d | 2016-05-23 11:53:14 -0700 | [diff] [blame] | 235 | [peer_connection.delegate peerConnection:peer_connection |
| 236 | didRemoveIceCandidates:ice_candidates]; |
| 237 | } |
| 238 | |
Alex Drake | 43faee0 | 2019-08-12 16:27:34 -0700 | [diff] [blame] | 239 | void PeerConnectionDelegateAdapter::OnIceSelectedCandidatePairChanged( |
| 240 | const cricket::CandidatePairChangeEvent &event) { |
Qingsi Wang | 7cdcda9 | 2019-08-28 09:18:37 -0700 | [diff] [blame] | 241 | const auto &selected_pair = event.selected_candidate_pair; |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 242 | auto local_candidate_wrapper = std::make_unique<JsepIceCandidate>( |
Qingsi Wang | 7cdcda9 | 2019-08-28 09:18:37 -0700 | [diff] [blame] | 243 | selected_pair.local_candidate().transport_name(), -1, selected_pair.local_candidate()); |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 244 | RTC_OBJC_TYPE(RTCIceCandidate) *local_candidate = [[RTC_OBJC_TYPE(RTCIceCandidate) alloc] |
| 245 | initWithNativeCandidate:local_candidate_wrapper.release()]; |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 246 | auto remote_candidate_wrapper = std::make_unique<JsepIceCandidate>( |
Qingsi Wang | 7cdcda9 | 2019-08-28 09:18:37 -0700 | [diff] [blame] | 247 | selected_pair.remote_candidate().transport_name(), -1, selected_pair.remote_candidate()); |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 248 | RTC_OBJC_TYPE(RTCIceCandidate) *remote_candidate = [[RTC_OBJC_TYPE(RTCIceCandidate) alloc] |
| 249 | initWithNativeCandidate:remote_candidate_wrapper.release()]; |
| 250 | RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; |
Alex Drake | 43faee0 | 2019-08-12 16:27:34 -0700 | [diff] [blame] | 251 | NSString *nsstr_reason = [NSString stringForStdString:event.reason]; |
| 252 | if ([peer_connection.delegate |
| 253 | respondsToSelector:@selector |
| 254 | (peerConnection:didChangeLocalCandidate:remoteCandidate:lastReceivedMs:changeReason:)]) { |
| 255 | [peer_connection.delegate peerConnection:peer_connection |
| 256 | didChangeLocalCandidate:local_candidate |
| 257 | remoteCandidate:remote_candidate |
| 258 | lastReceivedMs:event.last_data_received_ms |
| 259 | changeReason:nsstr_reason]; |
| 260 | } |
| 261 | } |
| 262 | |
Yura Yaroshevich | 546d7f9 | 2018-02-28 21:06:34 +0300 | [diff] [blame] | 263 | void PeerConnectionDelegateAdapter::OnAddTrack( |
| 264 | rtc::scoped_refptr<RtpReceiverInterface> receiver, |
Alex Drake | 43faee0 | 2019-08-12 16:27:34 -0700 | [diff] [blame] | 265 | const std::vector<rtc::scoped_refptr<MediaStreamInterface>> &streams) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 266 | RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; |
Alex Drake | 43faee0 | 2019-08-12 16:27:34 -0700 | [diff] [blame] | 267 | if ([peer_connection.delegate respondsToSelector:@selector(peerConnection: |
| 268 | didAddReceiver:streams:)]) { |
Yura Yaroshevich | 546d7f9 | 2018-02-28 21:06:34 +0300 | [diff] [blame] | 269 | NSMutableArray *mediaStreams = [NSMutableArray arrayWithCapacity:streams.size()]; |
Alex Drake | 43faee0 | 2019-08-12 16:27:34 -0700 | [diff] [blame] | 270 | for (const auto &nativeStream : streams) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 271 | RTC_OBJC_TYPE(RTCMediaStream) *mediaStream = |
| 272 | [[RTC_OBJC_TYPE(RTCMediaStream) alloc] initWithFactory:peer_connection.factory |
| 273 | nativeMediaStream:nativeStream]; |
Yura Yaroshevich | 546d7f9 | 2018-02-28 21:06:34 +0300 | [diff] [blame] | 274 | [mediaStreams addObject:mediaStream]; |
| 275 | } |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 276 | RTC_OBJC_TYPE(RTCRtpReceiver) *rtpReceiver = |
| 277 | [[RTC_OBJC_TYPE(RTCRtpReceiver) alloc] initWithFactory:peer_connection.factory |
| 278 | nativeRtpReceiver:receiver]; |
Yura Yaroshevich | 546d7f9 | 2018-02-28 21:06:34 +0300 | [diff] [blame] | 279 | |
| 280 | [peer_connection.delegate peerConnection:peer_connection |
| 281 | didAddReceiver:rtpReceiver |
| 282 | streams:mediaStreams]; |
| 283 | } |
| 284 | } |
| 285 | |
Zeke Chin | 8de502b | 2018-08-21 11:41:07 -0700 | [diff] [blame] | 286 | void PeerConnectionDelegateAdapter::OnRemoveTrack( |
| 287 | rtc::scoped_refptr<RtpReceiverInterface> receiver) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 288 | RTC_OBJC_TYPE(RTCPeerConnection) *peer_connection = peer_connection_; |
Zeke Chin | 8de502b | 2018-08-21 11:41:07 -0700 | [diff] [blame] | 289 | if ([peer_connection.delegate respondsToSelector:@selector(peerConnection:didRemoveReceiver:)]) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 290 | RTC_OBJC_TYPE(RTCRtpReceiver) *rtpReceiver = |
| 291 | [[RTC_OBJC_TYPE(RTCRtpReceiver) alloc] initWithFactory:peer_connection.factory |
| 292 | nativeRtpReceiver:receiver]; |
Zeke Chin | 8de502b | 2018-08-21 11:41:07 -0700 | [diff] [blame] | 293 | [peer_connection.delegate peerConnection:peer_connection didRemoveReceiver:rtpReceiver]; |
| 294 | } |
| 295 | } |
| 296 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 297 | } // namespace webrtc |
| 298 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 299 | @implementation RTC_OBJC_TYPE (RTCPeerConnection) { |
| 300 | RTC_OBJC_TYPE(RTCPeerConnectionFactory) * _factory; |
| 301 | NSMutableArray<RTC_OBJC_TYPE(RTCMediaStream) *> *_localStreams; |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 302 | std::unique_ptr<webrtc::PeerConnectionDelegateAdapter> _observer; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 303 | rtc::scoped_refptr<webrtc::PeerConnectionInterface> _peerConnection; |
deadbeef | 5d0b6d8 | 2017-01-09 16:05:28 -0800 | [diff] [blame] | 304 | std::unique_ptr<webrtc::MediaConstraints> _nativeConstraints; |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 305 | BOOL _hasStartedRtcEventLog; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | @synthesize delegate = _delegate; |
Yura Yaroshevich | c806c1d | 2018-06-21 12:51:11 +0300 | [diff] [blame] | 309 | @synthesize factory = _factory; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 310 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 311 | - (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory |
| 312 | configuration:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration |
| 313 | constraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints |
| 314 | delegate:(id<RTC_OBJC_TYPE(RTCPeerConnectionDelegate)>)delegate { |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 315 | NSParameterAssert(factory); |
Jonas Oreland | 285f83d | 2020-02-07 10:30:08 +0100 | [diff] [blame] | 316 | std::unique_ptr<webrtc::PeerConnectionDependencies> dependencies = |
| 317 | std::make_unique<webrtc::PeerConnectionDependencies>(nullptr); |
| 318 | return [self initWithDependencies:factory |
| 319 | configuration:configuration |
| 320 | constraints:constraints |
| 321 | dependencies:std::move(dependencies) |
| 322 | delegate:delegate]; |
| 323 | } |
| 324 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 325 | - (instancetype)initWithDependencies:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory |
| 326 | configuration:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration |
| 327 | constraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints |
Jonas Oreland | 285f83d | 2020-02-07 10:30:08 +0100 | [diff] [blame] | 328 | dependencies: |
| 329 | (std::unique_ptr<webrtc::PeerConnectionDependencies>)dependencies |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 330 | delegate:(id<RTC_OBJC_TYPE(RTCPeerConnectionDelegate)>)delegate { |
Jonas Oreland | 285f83d | 2020-02-07 10:30:08 +0100 | [diff] [blame] | 331 | NSParameterAssert(factory); |
| 332 | NSParameterAssert(dependencies.get()); |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 333 | std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> config( |
hbos | a73ca56 | 2016-05-17 03:28:58 -0700 | [diff] [blame] | 334 | [configuration createNativeConfiguration]); |
| 335 | if (!config) { |
| 336 | return nil; |
| 337 | } |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 338 | if (self = [super init]) { |
| 339 | _observer.reset(new webrtc::PeerConnectionDelegateAdapter(self)); |
deadbeef | 5d0b6d8 | 2017-01-09 16:05:28 -0800 | [diff] [blame] | 340 | _nativeConstraints = constraints.nativeConstraints; |
Jonas Oreland | 285f83d | 2020-02-07 10:30:08 +0100 | [diff] [blame] | 341 | CopyConstraintsIntoRtcConfiguration(_nativeConstraints.get(), config.get()); |
| 342 | |
| 343 | webrtc::PeerConnectionDependencies deps = std::move(*dependencies.release()); |
| 344 | deps.observer = _observer.get(); |
| 345 | _peerConnection = factory.nativeFactory->CreatePeerConnection(*config, std::move(deps)); |
| 346 | |
skvlad | 588783a | 2016-08-11 14:29:25 -0700 | [diff] [blame] | 347 | if (!_peerConnection) { |
| 348 | return nil; |
| 349 | } |
Yura Yaroshevich | 5297bd2 | 2018-06-19 12:51:51 +0300 | [diff] [blame] | 350 | _factory = factory; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 351 | _localStreams = [[NSMutableArray alloc] init]; |
| 352 | _delegate = delegate; |
| 353 | } |
| 354 | return self; |
| 355 | } |
| 356 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 357 | - (NSArray<RTC_OBJC_TYPE(RTCMediaStream) *> *)localStreams { |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 358 | return [_localStreams copy]; |
| 359 | } |
| 360 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 361 | - (RTC_OBJC_TYPE(RTCSessionDescription) *)localDescription { |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 362 | const webrtc::SessionDescriptionInterface *description = |
| 363 | _peerConnection->local_description(); |
| 364 | return description ? |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 365 | [[RTC_OBJC_TYPE(RTCSessionDescription) alloc] initWithNativeDescription:description] : |
| 366 | nil; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 367 | } |
| 368 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 369 | - (RTC_OBJC_TYPE(RTCSessionDescription) *)remoteDescription { |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 370 | const webrtc::SessionDescriptionInterface *description = |
| 371 | _peerConnection->remote_description(); |
| 372 | return description ? |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 373 | [[RTC_OBJC_TYPE(RTCSessionDescription) alloc] initWithNativeDescription:description] : |
| 374 | nil; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | - (RTCSignalingState)signalingState { |
| 378 | return [[self class] |
| 379 | signalingStateForNativeState:_peerConnection->signaling_state()]; |
| 380 | } |
| 381 | |
| 382 | - (RTCIceConnectionState)iceConnectionState { |
| 383 | return [[self class] iceConnectionStateForNativeState: |
| 384 | _peerConnection->ice_connection_state()]; |
| 385 | } |
| 386 | |
Jonas Olsson | cfddbb7 | 2018-11-15 16:52:45 +0100 | [diff] [blame] | 387 | - (RTCPeerConnectionState)connectionState { |
| 388 | return [[self class] connectionStateForNativeState:_peerConnection->peer_connection_state()]; |
| 389 | } |
| 390 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 391 | - (RTCIceGatheringState)iceGatheringState { |
| 392 | return [[self class] iceGatheringStateForNativeState: |
| 393 | _peerConnection->ice_gathering_state()]; |
| 394 | } |
| 395 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 396 | - (BOOL)setConfiguration:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration { |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 397 | std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> config( |
hbos | a73ca56 | 2016-05-17 03:28:58 -0700 | [diff] [blame] | 398 | [configuration createNativeConfiguration]); |
| 399 | if (!config) { |
| 400 | return NO; |
| 401 | } |
deadbeef | 5d0b6d8 | 2017-01-09 16:05:28 -0800 | [diff] [blame] | 402 | CopyConstraintsIntoRtcConfiguration(_nativeConstraints.get(), |
| 403 | config.get()); |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 404 | return _peerConnection->SetConfiguration(*config).ok(); |
tkchin | aac3eb2 | 2016-03-09 21:49:40 -0800 | [diff] [blame] | 405 | } |
| 406 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 407 | - (RTC_OBJC_TYPE(RTCConfiguration) *)configuration { |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 408 | webrtc::PeerConnectionInterface::RTCConfiguration config = |
| 409 | _peerConnection->GetConfiguration(); |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 410 | return [[RTC_OBJC_TYPE(RTCConfiguration) alloc] initWithNativeConfiguration:config]; |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 411 | } |
| 412 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 413 | - (void)close { |
| 414 | _peerConnection->Close(); |
| 415 | } |
| 416 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 417 | - (void)addIceCandidate:(RTC_OBJC_TYPE(RTCIceCandidate) *)candidate { |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 418 | std::unique_ptr<const webrtc::IceCandidateInterface> iceCandidate( |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 419 | candidate.nativeCandidate); |
| 420 | _peerConnection->AddIceCandidate(iceCandidate.get()); |
| 421 | } |
| 422 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 423 | - (void)removeIceCandidates:(NSArray<RTC_OBJC_TYPE(RTCIceCandidate) *> *)iceCandidates { |
Honghai Zhang | da2ba4d | 2016-05-23 11:53:14 -0700 | [diff] [blame] | 424 | std::vector<cricket::Candidate> candidates; |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 425 | for (RTC_OBJC_TYPE(RTCIceCandidate) * iceCandidate in iceCandidates) { |
Honghai Zhang | da2ba4d | 2016-05-23 11:53:14 -0700 | [diff] [blame] | 426 | std::unique_ptr<const webrtc::IceCandidateInterface> candidate( |
| 427 | iceCandidate.nativeCandidate); |
| 428 | if (candidate) { |
| 429 | candidates.push_back(candidate->candidate()); |
| 430 | // Need to fill the transport name from the sdp_mid. |
| 431 | candidates.back().set_transport_name(candidate->sdp_mid()); |
| 432 | } |
| 433 | } |
| 434 | if (!candidates.empty()) { |
| 435 | _peerConnection->RemoveIceCandidates(candidates); |
| 436 | } |
| 437 | } |
| 438 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 439 | - (void)addStream:(RTC_OBJC_TYPE(RTCMediaStream) *)stream { |
hjon | a2f7798 | 2016-03-04 07:09:09 -0800 | [diff] [blame] | 440 | if (!_peerConnection->AddStream(stream.nativeMediaStream)) { |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 441 | RTCLogError(@"Failed to add stream: %@", stream); |
| 442 | return; |
| 443 | } |
| 444 | [_localStreams addObject:stream]; |
| 445 | } |
| 446 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 447 | - (void)removeStream:(RTC_OBJC_TYPE(RTCMediaStream) *)stream { |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 448 | _peerConnection->RemoveStream(stream.nativeMediaStream); |
| 449 | [_localStreams removeObject:stream]; |
| 450 | } |
| 451 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 452 | - (RTC_OBJC_TYPE(RTCRtpSender) *)addTrack:(RTC_OBJC_TYPE(RTCMediaStreamTrack) *)track |
| 453 | streamIds:(NSArray<NSString *> *)streamIds { |
Seth Hampson | 513449e | 2018-03-06 09:35:56 -0800 | [diff] [blame] | 454 | std::vector<std::string> nativeStreamIds; |
| 455 | for (NSString *streamId in streamIds) { |
| 456 | nativeStreamIds.push_back([streamId UTF8String]); |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 457 | } |
| 458 | webrtc::RTCErrorOr<rtc::scoped_refptr<webrtc::RtpSenderInterface>> nativeSenderOrError = |
Seth Hampson | 513449e | 2018-03-06 09:35:56 -0800 | [diff] [blame] | 459 | _peerConnection->AddTrack(track.nativeTrack, nativeStreamIds); |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 460 | if (!nativeSenderOrError.ok()) { |
| 461 | RTCLogError(@"Failed to add track %@: %s", track, nativeSenderOrError.error().message()); |
| 462 | return nil; |
| 463 | } |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 464 | return [[RTC_OBJC_TYPE(RTCRtpSender) alloc] initWithFactory:self.factory |
| 465 | nativeRtpSender:nativeSenderOrError.MoveValue()]; |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 466 | } |
| 467 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 468 | - (BOOL)removeTrack:(RTC_OBJC_TYPE(RTCRtpSender) *)sender { |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 469 | bool result = _peerConnection->RemoveTrack(sender.nativeRtpSender); |
| 470 | if (!result) { |
| 471 | RTCLogError(@"Failed to remote track %@", sender); |
| 472 | } |
| 473 | return result; |
| 474 | } |
| 475 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 476 | - (RTC_OBJC_TYPE(RTCRtpTransceiver) *)addTransceiverWithTrack: |
| 477 | (RTC_OBJC_TYPE(RTCMediaStreamTrack) *)track { |
| 478 | return [self addTransceiverWithTrack:track |
| 479 | init:[[RTC_OBJC_TYPE(RTCRtpTransceiverInit) alloc] init]]; |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 480 | } |
| 481 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 482 | - (RTC_OBJC_TYPE(RTCRtpTransceiver) *) |
| 483 | addTransceiverWithTrack:(RTC_OBJC_TYPE(RTCMediaStreamTrack) *)track |
| 484 | init:(RTC_OBJC_TYPE(RTCRtpTransceiverInit) *)init { |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 485 | webrtc::RTCErrorOr<rtc::scoped_refptr<webrtc::RtpTransceiverInterface>> nativeTransceiverOrError = |
| 486 | _peerConnection->AddTransceiver(track.nativeTrack, init.nativeInit); |
| 487 | if (!nativeTransceiverOrError.ok()) { |
| 488 | RTCLogError( |
| 489 | @"Failed to add transceiver %@: %s", track, nativeTransceiverOrError.error().message()); |
| 490 | return nil; |
| 491 | } |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 492 | return [[RTC_OBJC_TYPE(RTCRtpTransceiver) alloc] |
| 493 | initWithFactory:self.factory |
| 494 | nativeRtpTransceiver:nativeTransceiverOrError.MoveValue()]; |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 495 | } |
| 496 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 497 | - (RTC_OBJC_TYPE(RTCRtpTransceiver) *)addTransceiverOfType:(RTCRtpMediaType)mediaType { |
| 498 | return [self addTransceiverOfType:mediaType |
| 499 | init:[[RTC_OBJC_TYPE(RTCRtpTransceiverInit) alloc] init]]; |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 500 | } |
| 501 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 502 | - (RTC_OBJC_TYPE(RTCRtpTransceiver) *)addTransceiverOfType:(RTCRtpMediaType)mediaType |
| 503 | init:(RTC_OBJC_TYPE(RTCRtpTransceiverInit) *) |
| 504 | init { |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 505 | webrtc::RTCErrorOr<rtc::scoped_refptr<webrtc::RtpTransceiverInterface>> nativeTransceiverOrError = |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 506 | _peerConnection->AddTransceiver( |
| 507 | [RTC_OBJC_TYPE(RTCRtpReceiver) nativeMediaTypeForMediaType:mediaType], init.nativeInit); |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 508 | if (!nativeTransceiverOrError.ok()) { |
| 509 | RTCLogError(@"Failed to add transceiver %@: %s", |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 510 | [RTC_OBJC_TYPE(RTCRtpReceiver) stringForMediaType:mediaType], |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 511 | nativeTransceiverOrError.error().message()); |
| 512 | return nil; |
| 513 | } |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 514 | return [[RTC_OBJC_TYPE(RTCRtpTransceiver) alloc] |
| 515 | initWithFactory:self.factory |
| 516 | nativeRtpTransceiver:nativeTransceiverOrError.MoveValue()]; |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 517 | } |
| 518 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 519 | - (void)offerForConstraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints |
| 520 | completionHandler:(void (^)(RTC_OBJC_TYPE(RTCSessionDescription) * sessionDescription, |
| 521 | NSError *error))completionHandler { |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 522 | rtc::scoped_refptr<webrtc::CreateSessionDescriptionObserverAdapter> |
| 523 | observer(new rtc::RefCountedObject |
| 524 | <webrtc::CreateSessionDescriptionObserverAdapter>(completionHandler)); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 525 | webrtc::PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 526 | CopyConstraintsIntoOfferAnswerOptions(constraints.nativeConstraints.get(), &options); |
| 527 | |
| 528 | _peerConnection->CreateOffer(observer, options); |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 529 | } |
| 530 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 531 | - (void)answerForConstraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints |
| 532 | completionHandler:(void (^)(RTC_OBJC_TYPE(RTCSessionDescription) * sessionDescription, |
| 533 | NSError *error))completionHandler { |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 534 | rtc::scoped_refptr<webrtc::CreateSessionDescriptionObserverAdapter> |
| 535 | observer(new rtc::RefCountedObject |
| 536 | <webrtc::CreateSessionDescriptionObserverAdapter>(completionHandler)); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 537 | webrtc::PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 538 | CopyConstraintsIntoOfferAnswerOptions(constraints.nativeConstraints.get(), &options); |
| 539 | |
| 540 | _peerConnection->CreateAnswer(observer, options); |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 541 | } |
| 542 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 543 | - (void)setLocalDescription:(RTC_OBJC_TYPE(RTCSessionDescription) *)sdp |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 544 | completionHandler:(void (^)(NSError *error))completionHandler { |
| 545 | rtc::scoped_refptr<webrtc::SetSessionDescriptionObserverAdapter> observer( |
| 546 | new rtc::RefCountedObject<webrtc::SetSessionDescriptionObserverAdapter>( |
| 547 | completionHandler)); |
| 548 | _peerConnection->SetLocalDescription(observer, sdp.nativeDescription); |
| 549 | } |
| 550 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 551 | - (void)setRemoteDescription:(RTC_OBJC_TYPE(RTCSessionDescription) *)sdp |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 552 | completionHandler:(void (^)(NSError *error))completionHandler { |
| 553 | rtc::scoped_refptr<webrtc::SetSessionDescriptionObserverAdapter> observer( |
| 554 | new rtc::RefCountedObject<webrtc::SetSessionDescriptionObserverAdapter>( |
| 555 | completionHandler)); |
| 556 | _peerConnection->SetRemoteDescription(observer, sdp.nativeDescription); |
| 557 | } |
| 558 | |
zstein | 8b47617 | 2017-09-05 14:43:03 -0700 | [diff] [blame] | 559 | - (BOOL)setBweMinBitrateBps:(nullable NSNumber *)minBitrateBps |
| 560 | currentBitrateBps:(nullable NSNumber *)currentBitrateBps |
| 561 | maxBitrateBps:(nullable NSNumber *)maxBitrateBps { |
zstein | 03adb7c | 2017-08-09 14:29:42 -0700 | [diff] [blame] | 562 | webrtc::PeerConnectionInterface::BitrateParameters params; |
| 563 | if (minBitrateBps != nil) { |
Danil Chapovalov | 196100e | 2018-06-21 10:17:24 +0200 | [diff] [blame] | 564 | params.min_bitrate_bps = absl::optional<int>(minBitrateBps.intValue); |
zstein | 03adb7c | 2017-08-09 14:29:42 -0700 | [diff] [blame] | 565 | } |
| 566 | if (currentBitrateBps != nil) { |
Danil Chapovalov | 196100e | 2018-06-21 10:17:24 +0200 | [diff] [blame] | 567 | params.current_bitrate_bps = absl::optional<int>(currentBitrateBps.intValue); |
zstein | 03adb7c | 2017-08-09 14:29:42 -0700 | [diff] [blame] | 568 | } |
| 569 | if (maxBitrateBps != nil) { |
Danil Chapovalov | 196100e | 2018-06-21 10:17:24 +0200 | [diff] [blame] | 570 | params.max_bitrate_bps = absl::optional<int>(maxBitrateBps.intValue); |
zstein | 03adb7c | 2017-08-09 14:29:42 -0700 | [diff] [blame] | 571 | } |
| 572 | return _peerConnection->SetBitrate(params).ok(); |
| 573 | } |
| 574 | |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 575 | - (BOOL)startRtcEventLogWithFilePath:(NSString *)filePath |
| 576 | maxSizeInBytes:(int64_t)maxSizeInBytes { |
| 577 | RTC_DCHECK(filePath.length); |
| 578 | RTC_DCHECK_GT(maxSizeInBytes, 0); |
| 579 | RTC_DCHECK(!_hasStartedRtcEventLog); |
| 580 | if (_hasStartedRtcEventLog) { |
| 581 | RTCLogError(@"Event logging already started."); |
| 582 | return NO; |
| 583 | } |
Niels Möller | dec9f74 | 2019-06-03 15:25:20 +0200 | [diff] [blame] | 584 | FILE *f = fopen(filePath.UTF8String, "wb"); |
| 585 | if (!f) { |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 586 | RTCLogError(@"Error opening file: %@. Error: %d", filePath, errno); |
| 587 | return NO; |
| 588 | } |
Niels Möller | 695cf6a | 2019-05-13 12:27:23 +0200 | [diff] [blame] | 589 | // TODO(eladalon): It would be better to not allow negative values into PC. |
| 590 | const size_t max_size = (maxSizeInBytes < 0) ? webrtc::RtcEventLog::kUnlimitedOutput : |
| 591 | rtc::saturated_cast<size_t>(maxSizeInBytes); |
| 592 | |
| 593 | _hasStartedRtcEventLog = _peerConnection->StartRtcEventLog( |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 594 | std::make_unique<webrtc::RtcEventLogOutputFile>(f, max_size)); |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 595 | return _hasStartedRtcEventLog; |
| 596 | } |
| 597 | |
| 598 | - (void)stopRtcEventLog { |
| 599 | _peerConnection->StopRtcEventLog(); |
| 600 | _hasStartedRtcEventLog = NO; |
| 601 | } |
| 602 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 603 | - (RTC_OBJC_TYPE(RTCRtpSender) *)senderWithKind:(NSString *)kind streamId:(NSString *)streamId { |
skvlad | f3569c8 | 2016-04-29 15:30:16 -0700 | [diff] [blame] | 604 | std::string nativeKind = [NSString stdStringForString:kind]; |
| 605 | std::string nativeStreamId = [NSString stdStringForString:streamId]; |
| 606 | rtc::scoped_refptr<webrtc::RtpSenderInterface> nativeSender( |
| 607 | _peerConnection->CreateSender(nativeKind, nativeStreamId)); |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 608 | return nativeSender ? [[RTC_OBJC_TYPE(RTCRtpSender) alloc] initWithFactory:self.factory |
| 609 | nativeRtpSender:nativeSender] : |
| 610 | nil; |
skvlad | f3569c8 | 2016-04-29 15:30:16 -0700 | [diff] [blame] | 611 | } |
| 612 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 613 | - (NSArray<RTC_OBJC_TYPE(RTCRtpSender) *> *)senders { |
skvlad | 79b4b87 | 2016-04-08 17:28:55 -0700 | [diff] [blame] | 614 | std::vector<rtc::scoped_refptr<webrtc::RtpSenderInterface>> nativeSenders( |
| 615 | _peerConnection->GetSenders()); |
| 616 | NSMutableArray *senders = [[NSMutableArray alloc] init]; |
| 617 | for (const auto &nativeSender : nativeSenders) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 618 | RTC_OBJC_TYPE(RTCRtpSender) *sender = |
| 619 | [[RTC_OBJC_TYPE(RTCRtpSender) alloc] initWithFactory:self.factory |
| 620 | nativeRtpSender:nativeSender]; |
skvlad | 79b4b87 | 2016-04-08 17:28:55 -0700 | [diff] [blame] | 621 | [senders addObject:sender]; |
| 622 | } |
| 623 | return senders; |
| 624 | } |
| 625 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 626 | - (NSArray<RTC_OBJC_TYPE(RTCRtpReceiver) *> *)receivers { |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 627 | std::vector<rtc::scoped_refptr<webrtc::RtpReceiverInterface>> nativeReceivers( |
| 628 | _peerConnection->GetReceivers()); |
| 629 | NSMutableArray *receivers = [[NSMutableArray alloc] init]; |
| 630 | for (const auto &nativeReceiver : nativeReceivers) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 631 | RTC_OBJC_TYPE(RTCRtpReceiver) *receiver = |
| 632 | [[RTC_OBJC_TYPE(RTCRtpReceiver) alloc] initWithFactory:self.factory |
| 633 | nativeRtpReceiver:nativeReceiver]; |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 634 | [receivers addObject:receiver]; |
| 635 | } |
| 636 | return receivers; |
| 637 | } |
| 638 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 639 | - (NSArray<RTC_OBJC_TYPE(RTCRtpTransceiver) *> *)transceivers { |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 640 | std::vector<rtc::scoped_refptr<webrtc::RtpTransceiverInterface>> nativeTransceivers( |
| 641 | _peerConnection->GetTransceivers()); |
| 642 | NSMutableArray *transceivers = [[NSMutableArray alloc] init]; |
Mirko Bonadei | 739baf0 | 2019-01-27 17:29:42 +0100 | [diff] [blame] | 643 | for (const auto &nativeTransceiver : nativeTransceivers) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame^] | 644 | RTC_OBJC_TYPE(RTCRtpTransceiver) *transceiver = |
| 645 | [[RTC_OBJC_TYPE(RTCRtpTransceiver) alloc] initWithFactory:self.factory |
| 646 | nativeRtpTransceiver:nativeTransceiver]; |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 647 | [transceivers addObject:transceiver]; |
| 648 | } |
| 649 | return transceivers; |
| 650 | } |
| 651 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 652 | #pragma mark - Private |
| 653 | |
| 654 | + (webrtc::PeerConnectionInterface::SignalingState)nativeSignalingStateForState: |
| 655 | (RTCSignalingState)state { |
| 656 | switch (state) { |
| 657 | case RTCSignalingStateStable: |
| 658 | return webrtc::PeerConnectionInterface::kStable; |
| 659 | case RTCSignalingStateHaveLocalOffer: |
| 660 | return webrtc::PeerConnectionInterface::kHaveLocalOffer; |
| 661 | case RTCSignalingStateHaveLocalPrAnswer: |
| 662 | return webrtc::PeerConnectionInterface::kHaveLocalPrAnswer; |
| 663 | case RTCSignalingStateHaveRemoteOffer: |
| 664 | return webrtc::PeerConnectionInterface::kHaveRemoteOffer; |
| 665 | case RTCSignalingStateHaveRemotePrAnswer: |
| 666 | return webrtc::PeerConnectionInterface::kHaveRemotePrAnswer; |
| 667 | case RTCSignalingStateClosed: |
| 668 | return webrtc::PeerConnectionInterface::kClosed; |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | + (RTCSignalingState)signalingStateForNativeState: |
| 673 | (webrtc::PeerConnectionInterface::SignalingState)nativeState { |
| 674 | switch (nativeState) { |
| 675 | case webrtc::PeerConnectionInterface::kStable: |
| 676 | return RTCSignalingStateStable; |
| 677 | case webrtc::PeerConnectionInterface::kHaveLocalOffer: |
| 678 | return RTCSignalingStateHaveLocalOffer; |
| 679 | case webrtc::PeerConnectionInterface::kHaveLocalPrAnswer: |
| 680 | return RTCSignalingStateHaveLocalPrAnswer; |
| 681 | case webrtc::PeerConnectionInterface::kHaveRemoteOffer: |
| 682 | return RTCSignalingStateHaveRemoteOffer; |
| 683 | case webrtc::PeerConnectionInterface::kHaveRemotePrAnswer: |
| 684 | return RTCSignalingStateHaveRemotePrAnswer; |
| 685 | case webrtc::PeerConnectionInterface::kClosed: |
| 686 | return RTCSignalingStateClosed; |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | + (NSString *)stringForSignalingState:(RTCSignalingState)state { |
| 691 | switch (state) { |
| 692 | case RTCSignalingStateStable: |
| 693 | return @"STABLE"; |
| 694 | case RTCSignalingStateHaveLocalOffer: |
| 695 | return @"HAVE_LOCAL_OFFER"; |
| 696 | case RTCSignalingStateHaveLocalPrAnswer: |
| 697 | return @"HAVE_LOCAL_PRANSWER"; |
| 698 | case RTCSignalingStateHaveRemoteOffer: |
| 699 | return @"HAVE_REMOTE_OFFER"; |
| 700 | case RTCSignalingStateHaveRemotePrAnswer: |
| 701 | return @"HAVE_REMOTE_PRANSWER"; |
| 702 | case RTCSignalingStateClosed: |
| 703 | return @"CLOSED"; |
| 704 | } |
| 705 | } |
| 706 | |
Jonas Olsson | cfddbb7 | 2018-11-15 16:52:45 +0100 | [diff] [blame] | 707 | + (webrtc::PeerConnectionInterface::PeerConnectionState)nativeConnectionStateForState: |
| 708 | (RTCPeerConnectionState)state { |
| 709 | switch (state) { |
| 710 | case RTCPeerConnectionStateNew: |
| 711 | return webrtc::PeerConnectionInterface::PeerConnectionState::kNew; |
| 712 | case RTCPeerConnectionStateConnecting: |
| 713 | return webrtc::PeerConnectionInterface::PeerConnectionState::kConnecting; |
| 714 | case RTCPeerConnectionStateConnected: |
| 715 | return webrtc::PeerConnectionInterface::PeerConnectionState::kConnected; |
| 716 | case RTCPeerConnectionStateFailed: |
| 717 | return webrtc::PeerConnectionInterface::PeerConnectionState::kFailed; |
| 718 | case RTCPeerConnectionStateDisconnected: |
| 719 | return webrtc::PeerConnectionInterface::PeerConnectionState::kDisconnected; |
| 720 | case RTCPeerConnectionStateClosed: |
| 721 | return webrtc::PeerConnectionInterface::PeerConnectionState::kClosed; |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | + (RTCPeerConnectionState)connectionStateForNativeState: |
| 726 | (webrtc::PeerConnectionInterface::PeerConnectionState)nativeState { |
| 727 | switch (nativeState) { |
| 728 | case webrtc::PeerConnectionInterface::PeerConnectionState::kNew: |
| 729 | return RTCPeerConnectionStateNew; |
| 730 | case webrtc::PeerConnectionInterface::PeerConnectionState::kConnecting: |
| 731 | return RTCPeerConnectionStateConnecting; |
| 732 | case webrtc::PeerConnectionInterface::PeerConnectionState::kConnected: |
| 733 | return RTCPeerConnectionStateConnected; |
| 734 | case webrtc::PeerConnectionInterface::PeerConnectionState::kFailed: |
| 735 | return RTCPeerConnectionStateFailed; |
| 736 | case webrtc::PeerConnectionInterface::PeerConnectionState::kDisconnected: |
| 737 | return RTCPeerConnectionStateDisconnected; |
| 738 | case webrtc::PeerConnectionInterface::PeerConnectionState::kClosed: |
| 739 | return RTCPeerConnectionStateClosed; |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | + (NSString *)stringForConnectionState:(RTCPeerConnectionState)state { |
| 744 | switch (state) { |
| 745 | case RTCPeerConnectionStateNew: |
| 746 | return @"NEW"; |
| 747 | case RTCPeerConnectionStateConnecting: |
| 748 | return @"CONNECTING"; |
| 749 | case RTCPeerConnectionStateConnected: |
| 750 | return @"CONNECTED"; |
| 751 | case RTCPeerConnectionStateFailed: |
| 752 | return @"FAILED"; |
| 753 | case RTCPeerConnectionStateDisconnected: |
| 754 | return @"DISCONNECTED"; |
| 755 | case RTCPeerConnectionStateClosed: |
| 756 | return @"CLOSED"; |
| 757 | } |
| 758 | } |
| 759 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 760 | + (webrtc::PeerConnectionInterface::IceConnectionState) |
| 761 | nativeIceConnectionStateForState:(RTCIceConnectionState)state { |
| 762 | switch (state) { |
| 763 | case RTCIceConnectionStateNew: |
| 764 | return webrtc::PeerConnectionInterface::kIceConnectionNew; |
| 765 | case RTCIceConnectionStateChecking: |
| 766 | return webrtc::PeerConnectionInterface::kIceConnectionChecking; |
| 767 | case RTCIceConnectionStateConnected: |
| 768 | return webrtc::PeerConnectionInterface::kIceConnectionConnected; |
| 769 | case RTCIceConnectionStateCompleted: |
| 770 | return webrtc::PeerConnectionInterface::kIceConnectionCompleted; |
| 771 | case RTCIceConnectionStateFailed: |
| 772 | return webrtc::PeerConnectionInterface::kIceConnectionFailed; |
| 773 | case RTCIceConnectionStateDisconnected: |
| 774 | return webrtc::PeerConnectionInterface::kIceConnectionDisconnected; |
| 775 | case RTCIceConnectionStateClosed: |
| 776 | return webrtc::PeerConnectionInterface::kIceConnectionClosed; |
hjon | 8bbbf2c | 2016-03-14 13:15:44 -0700 | [diff] [blame] | 777 | case RTCIceConnectionStateCount: |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 778 | return webrtc::PeerConnectionInterface::kIceConnectionMax; |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | + (RTCIceConnectionState)iceConnectionStateForNativeState: |
| 783 | (webrtc::PeerConnectionInterface::IceConnectionState)nativeState { |
| 784 | switch (nativeState) { |
| 785 | case webrtc::PeerConnectionInterface::kIceConnectionNew: |
| 786 | return RTCIceConnectionStateNew; |
| 787 | case webrtc::PeerConnectionInterface::kIceConnectionChecking: |
| 788 | return RTCIceConnectionStateChecking; |
| 789 | case webrtc::PeerConnectionInterface::kIceConnectionConnected: |
| 790 | return RTCIceConnectionStateConnected; |
| 791 | case webrtc::PeerConnectionInterface::kIceConnectionCompleted: |
| 792 | return RTCIceConnectionStateCompleted; |
| 793 | case webrtc::PeerConnectionInterface::kIceConnectionFailed: |
| 794 | return RTCIceConnectionStateFailed; |
| 795 | case webrtc::PeerConnectionInterface::kIceConnectionDisconnected: |
| 796 | return RTCIceConnectionStateDisconnected; |
| 797 | case webrtc::PeerConnectionInterface::kIceConnectionClosed: |
| 798 | return RTCIceConnectionStateClosed; |
| 799 | case webrtc::PeerConnectionInterface::kIceConnectionMax: |
hjon | 8bbbf2c | 2016-03-14 13:15:44 -0700 | [diff] [blame] | 800 | return RTCIceConnectionStateCount; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 801 | } |
| 802 | } |
| 803 | |
| 804 | + (NSString *)stringForIceConnectionState:(RTCIceConnectionState)state { |
| 805 | switch (state) { |
| 806 | case RTCIceConnectionStateNew: |
| 807 | return @"NEW"; |
| 808 | case RTCIceConnectionStateChecking: |
| 809 | return @"CHECKING"; |
| 810 | case RTCIceConnectionStateConnected: |
| 811 | return @"CONNECTED"; |
| 812 | case RTCIceConnectionStateCompleted: |
| 813 | return @"COMPLETED"; |
| 814 | case RTCIceConnectionStateFailed: |
| 815 | return @"FAILED"; |
| 816 | case RTCIceConnectionStateDisconnected: |
| 817 | return @"DISCONNECTED"; |
| 818 | case RTCIceConnectionStateClosed: |
| 819 | return @"CLOSED"; |
hjon | 8bbbf2c | 2016-03-14 13:15:44 -0700 | [diff] [blame] | 820 | case RTCIceConnectionStateCount: |
| 821 | return @"COUNT"; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 822 | } |
| 823 | } |
| 824 | |
| 825 | + (webrtc::PeerConnectionInterface::IceGatheringState) |
| 826 | nativeIceGatheringStateForState:(RTCIceGatheringState)state { |
| 827 | switch (state) { |
| 828 | case RTCIceGatheringStateNew: |
| 829 | return webrtc::PeerConnectionInterface::kIceGatheringNew; |
| 830 | case RTCIceGatheringStateGathering: |
| 831 | return webrtc::PeerConnectionInterface::kIceGatheringGathering; |
| 832 | case RTCIceGatheringStateComplete: |
| 833 | return webrtc::PeerConnectionInterface::kIceGatheringComplete; |
| 834 | } |
| 835 | } |
| 836 | |
| 837 | + (RTCIceGatheringState)iceGatheringStateForNativeState: |
| 838 | (webrtc::PeerConnectionInterface::IceGatheringState)nativeState { |
| 839 | switch (nativeState) { |
| 840 | case webrtc::PeerConnectionInterface::kIceGatheringNew: |
| 841 | return RTCIceGatheringStateNew; |
| 842 | case webrtc::PeerConnectionInterface::kIceGatheringGathering: |
| 843 | return RTCIceGatheringStateGathering; |
| 844 | case webrtc::PeerConnectionInterface::kIceGatheringComplete: |
| 845 | return RTCIceGatheringStateComplete; |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | + (NSString *)stringForIceGatheringState:(RTCIceGatheringState)state { |
| 850 | switch (state) { |
| 851 | case RTCIceGatheringStateNew: |
| 852 | return @"NEW"; |
| 853 | case RTCIceGatheringStateGathering: |
| 854 | return @"GATHERING"; |
| 855 | case RTCIceGatheringStateComplete: |
| 856 | return @"COMPLETE"; |
| 857 | } |
| 858 | } |
| 859 | |
| 860 | + (webrtc::PeerConnectionInterface::StatsOutputLevel) |
| 861 | nativeStatsOutputLevelForLevel:(RTCStatsOutputLevel)level { |
| 862 | switch (level) { |
| 863 | case RTCStatsOutputLevelStandard: |
| 864 | return webrtc::PeerConnectionInterface::kStatsOutputLevelStandard; |
| 865 | case RTCStatsOutputLevelDebug: |
| 866 | return webrtc::PeerConnectionInterface::kStatsOutputLevelDebug; |
| 867 | } |
| 868 | } |
| 869 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 870 | - (rtc::scoped_refptr<webrtc::PeerConnectionInterface>)nativePeerConnection { |
| 871 | return _peerConnection; |
| 872 | } |
| 873 | |
| 874 | @end |