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