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 { |
Taylor Brandstetter | c88fe70 | 2020-08-03 16:36:16 -0700 | [diff] [blame^] | 361 | // It's only safe to operate on SessionDescriptionInterface on the signaling thread. |
| 362 | return _peerConnection->signaling_thread()->Invoke<RTC_OBJC_TYPE(RTCSessionDescription) *>( |
| 363 | RTC_FROM_HERE, [self] { |
| 364 | const webrtc::SessionDescriptionInterface *description = |
| 365 | _peerConnection->local_description(); |
| 366 | return description ? |
| 367 | [[RTC_OBJC_TYPE(RTCSessionDescription) alloc] initWithNativeDescription:description] : |
| 368 | nil; |
| 369 | }); |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 370 | } |
| 371 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 372 | - (RTC_OBJC_TYPE(RTCSessionDescription) *)remoteDescription { |
Taylor Brandstetter | c88fe70 | 2020-08-03 16:36:16 -0700 | [diff] [blame^] | 373 | // It's only safe to operate on SessionDescriptionInterface on the signaling thread. |
| 374 | return _peerConnection->signaling_thread()->Invoke<RTC_OBJC_TYPE(RTCSessionDescription) *>( |
| 375 | RTC_FROM_HERE, [self] { |
| 376 | const webrtc::SessionDescriptionInterface *description = |
| 377 | _peerConnection->remote_description(); |
| 378 | return description ? |
| 379 | [[RTC_OBJC_TYPE(RTCSessionDescription) alloc] initWithNativeDescription:description] : |
| 380 | nil; |
| 381 | }); |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | - (RTCSignalingState)signalingState { |
| 385 | return [[self class] |
| 386 | signalingStateForNativeState:_peerConnection->signaling_state()]; |
| 387 | } |
| 388 | |
| 389 | - (RTCIceConnectionState)iceConnectionState { |
| 390 | return [[self class] iceConnectionStateForNativeState: |
| 391 | _peerConnection->ice_connection_state()]; |
| 392 | } |
| 393 | |
Jonas Olsson | cfddbb7 | 2018-11-15 16:52:45 +0100 | [diff] [blame] | 394 | - (RTCPeerConnectionState)connectionState { |
| 395 | return [[self class] connectionStateForNativeState:_peerConnection->peer_connection_state()]; |
| 396 | } |
| 397 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 398 | - (RTCIceGatheringState)iceGatheringState { |
| 399 | return [[self class] iceGatheringStateForNativeState: |
| 400 | _peerConnection->ice_gathering_state()]; |
| 401 | } |
| 402 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 403 | - (BOOL)setConfiguration:(RTC_OBJC_TYPE(RTCConfiguration) *)configuration { |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 404 | std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> config( |
hbos | a73ca56 | 2016-05-17 03:28:58 -0700 | [diff] [blame] | 405 | [configuration createNativeConfiguration]); |
| 406 | if (!config) { |
| 407 | return NO; |
| 408 | } |
deadbeef | 5d0b6d8 | 2017-01-09 16:05:28 -0800 | [diff] [blame] | 409 | CopyConstraintsIntoRtcConfiguration(_nativeConstraints.get(), |
| 410 | config.get()); |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 411 | return _peerConnection->SetConfiguration(*config).ok(); |
tkchin | aac3eb2 | 2016-03-09 21:49:40 -0800 | [diff] [blame] | 412 | } |
| 413 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 414 | - (RTC_OBJC_TYPE(RTCConfiguration) *)configuration { |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 415 | webrtc::PeerConnectionInterface::RTCConfiguration config = |
| 416 | _peerConnection->GetConfiguration(); |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 417 | return [[RTC_OBJC_TYPE(RTCConfiguration) alloc] initWithNativeConfiguration:config]; |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 418 | } |
| 419 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 420 | - (void)close { |
| 421 | _peerConnection->Close(); |
| 422 | } |
| 423 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 424 | - (void)addIceCandidate:(RTC_OBJC_TYPE(RTCIceCandidate) *)candidate { |
kwiberg | bfefb03 | 2016-05-01 14:53:46 -0700 | [diff] [blame] | 425 | std::unique_ptr<const webrtc::IceCandidateInterface> iceCandidate( |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 426 | candidate.nativeCandidate); |
| 427 | _peerConnection->AddIceCandidate(iceCandidate.get()); |
| 428 | } |
| 429 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 430 | - (void)removeIceCandidates:(NSArray<RTC_OBJC_TYPE(RTCIceCandidate) *> *)iceCandidates { |
Honghai Zhang | da2ba4d | 2016-05-23 11:53:14 -0700 | [diff] [blame] | 431 | std::vector<cricket::Candidate> candidates; |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 432 | for (RTC_OBJC_TYPE(RTCIceCandidate) * iceCandidate in iceCandidates) { |
Honghai Zhang | da2ba4d | 2016-05-23 11:53:14 -0700 | [diff] [blame] | 433 | std::unique_ptr<const webrtc::IceCandidateInterface> candidate( |
| 434 | iceCandidate.nativeCandidate); |
| 435 | if (candidate) { |
| 436 | candidates.push_back(candidate->candidate()); |
| 437 | // Need to fill the transport name from the sdp_mid. |
| 438 | candidates.back().set_transport_name(candidate->sdp_mid()); |
| 439 | } |
| 440 | } |
| 441 | if (!candidates.empty()) { |
| 442 | _peerConnection->RemoveIceCandidates(candidates); |
| 443 | } |
| 444 | } |
| 445 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 446 | - (void)addStream:(RTC_OBJC_TYPE(RTCMediaStream) *)stream { |
hjon | a2f7798 | 2016-03-04 07:09:09 -0800 | [diff] [blame] | 447 | if (!_peerConnection->AddStream(stream.nativeMediaStream)) { |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 448 | RTCLogError(@"Failed to add stream: %@", stream); |
| 449 | return; |
| 450 | } |
| 451 | [_localStreams addObject:stream]; |
| 452 | } |
| 453 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 454 | - (void)removeStream:(RTC_OBJC_TYPE(RTCMediaStream) *)stream { |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 455 | _peerConnection->RemoveStream(stream.nativeMediaStream); |
| 456 | [_localStreams removeObject:stream]; |
| 457 | } |
| 458 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 459 | - (RTC_OBJC_TYPE(RTCRtpSender) *)addTrack:(RTC_OBJC_TYPE(RTCMediaStreamTrack) *)track |
| 460 | streamIds:(NSArray<NSString *> *)streamIds { |
Seth Hampson | 513449e | 2018-03-06 09:35:56 -0800 | [diff] [blame] | 461 | std::vector<std::string> nativeStreamIds; |
| 462 | for (NSString *streamId in streamIds) { |
| 463 | nativeStreamIds.push_back([streamId UTF8String]); |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 464 | } |
| 465 | webrtc::RTCErrorOr<rtc::scoped_refptr<webrtc::RtpSenderInterface>> nativeSenderOrError = |
Seth Hampson | 513449e | 2018-03-06 09:35:56 -0800 | [diff] [blame] | 466 | _peerConnection->AddTrack(track.nativeTrack, nativeStreamIds); |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 467 | if (!nativeSenderOrError.ok()) { |
| 468 | RTCLogError(@"Failed to add track %@: %s", track, nativeSenderOrError.error().message()); |
| 469 | return nil; |
| 470 | } |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 471 | return [[RTC_OBJC_TYPE(RTCRtpSender) alloc] initWithFactory:self.factory |
| 472 | nativeRtpSender:nativeSenderOrError.MoveValue()]; |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 473 | } |
| 474 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 475 | - (BOOL)removeTrack:(RTC_OBJC_TYPE(RTCRtpSender) *)sender { |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 476 | bool result = _peerConnection->RemoveTrack(sender.nativeRtpSender); |
| 477 | if (!result) { |
| 478 | RTCLogError(@"Failed to remote track %@", sender); |
| 479 | } |
| 480 | return result; |
| 481 | } |
| 482 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 483 | - (RTC_OBJC_TYPE(RTCRtpTransceiver) *)addTransceiverWithTrack: |
| 484 | (RTC_OBJC_TYPE(RTCMediaStreamTrack) *)track { |
| 485 | return [self addTransceiverWithTrack:track |
| 486 | init:[[RTC_OBJC_TYPE(RTCRtpTransceiverInit) alloc] init]]; |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 487 | } |
| 488 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 489 | - (RTC_OBJC_TYPE(RTCRtpTransceiver) *) |
| 490 | addTransceiverWithTrack:(RTC_OBJC_TYPE(RTCMediaStreamTrack) *)track |
| 491 | init:(RTC_OBJC_TYPE(RTCRtpTransceiverInit) *)init { |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 492 | webrtc::RTCErrorOr<rtc::scoped_refptr<webrtc::RtpTransceiverInterface>> nativeTransceiverOrError = |
| 493 | _peerConnection->AddTransceiver(track.nativeTrack, init.nativeInit); |
| 494 | if (!nativeTransceiverOrError.ok()) { |
| 495 | RTCLogError( |
| 496 | @"Failed to add transceiver %@: %s", track, nativeTransceiverOrError.error().message()); |
| 497 | return nil; |
| 498 | } |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 499 | return [[RTC_OBJC_TYPE(RTCRtpTransceiver) alloc] |
| 500 | initWithFactory:self.factory |
| 501 | nativeRtpTransceiver:nativeTransceiverOrError.MoveValue()]; |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 502 | } |
| 503 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 504 | - (RTC_OBJC_TYPE(RTCRtpTransceiver) *)addTransceiverOfType:(RTCRtpMediaType)mediaType { |
| 505 | return [self addTransceiverOfType:mediaType |
| 506 | init:[[RTC_OBJC_TYPE(RTCRtpTransceiverInit) alloc] init]]; |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 507 | } |
| 508 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 509 | - (RTC_OBJC_TYPE(RTCRtpTransceiver) *)addTransceiverOfType:(RTCRtpMediaType)mediaType |
| 510 | init:(RTC_OBJC_TYPE(RTCRtpTransceiverInit) *) |
| 511 | init { |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 512 | webrtc::RTCErrorOr<rtc::scoped_refptr<webrtc::RtpTransceiverInterface>> nativeTransceiverOrError = |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 513 | _peerConnection->AddTransceiver( |
| 514 | [RTC_OBJC_TYPE(RTCRtpReceiver) nativeMediaTypeForMediaType:mediaType], init.nativeInit); |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 515 | if (!nativeTransceiverOrError.ok()) { |
| 516 | RTCLogError(@"Failed to add transceiver %@: %s", |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 517 | [RTC_OBJC_TYPE(RTCRtpReceiver) stringForMediaType:mediaType], |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 518 | nativeTransceiverOrError.error().message()); |
| 519 | return nil; |
| 520 | } |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 521 | return [[RTC_OBJC_TYPE(RTCRtpTransceiver) alloc] |
| 522 | initWithFactory:self.factory |
| 523 | nativeRtpTransceiver:nativeTransceiverOrError.MoveValue()]; |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 524 | } |
| 525 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 526 | - (void)offerForConstraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints |
| 527 | completionHandler:(void (^)(RTC_OBJC_TYPE(RTCSessionDescription) * sessionDescription, |
| 528 | NSError *error))completionHandler { |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 529 | rtc::scoped_refptr<webrtc::CreateSessionDescriptionObserverAdapter> |
| 530 | observer(new rtc::RefCountedObject |
| 531 | <webrtc::CreateSessionDescriptionObserverAdapter>(completionHandler)); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 532 | webrtc::PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 533 | CopyConstraintsIntoOfferAnswerOptions(constraints.nativeConstraints.get(), &options); |
| 534 | |
| 535 | _peerConnection->CreateOffer(observer, options); |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 536 | } |
| 537 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 538 | - (void)answerForConstraints:(RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints |
| 539 | completionHandler:(void (^)(RTC_OBJC_TYPE(RTCSessionDescription) * sessionDescription, |
| 540 | NSError *error))completionHandler { |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 541 | rtc::scoped_refptr<webrtc::CreateSessionDescriptionObserverAdapter> |
| 542 | observer(new rtc::RefCountedObject |
| 543 | <webrtc::CreateSessionDescriptionObserverAdapter>(completionHandler)); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 544 | webrtc::PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 545 | CopyConstraintsIntoOfferAnswerOptions(constraints.nativeConstraints.get(), &options); |
| 546 | |
| 547 | _peerConnection->CreateAnswer(observer, options); |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 548 | } |
| 549 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 550 | - (void)setLocalDescription:(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->SetLocalDescription(observer, sdp.nativeDescription); |
| 556 | } |
| 557 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 558 | - (void)setRemoteDescription:(RTC_OBJC_TYPE(RTCSessionDescription) *)sdp |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 559 | completionHandler:(void (^)(NSError *error))completionHandler { |
| 560 | rtc::scoped_refptr<webrtc::SetSessionDescriptionObserverAdapter> observer( |
| 561 | new rtc::RefCountedObject<webrtc::SetSessionDescriptionObserverAdapter>( |
| 562 | completionHandler)); |
| 563 | _peerConnection->SetRemoteDescription(observer, sdp.nativeDescription); |
| 564 | } |
| 565 | |
zstein | 8b47617 | 2017-09-05 14:43:03 -0700 | [diff] [blame] | 566 | - (BOOL)setBweMinBitrateBps:(nullable NSNumber *)minBitrateBps |
| 567 | currentBitrateBps:(nullable NSNumber *)currentBitrateBps |
| 568 | maxBitrateBps:(nullable NSNumber *)maxBitrateBps { |
Niels Möller | 9ad1f6f | 2020-07-13 10:25:41 +0200 | [diff] [blame] | 569 | webrtc::BitrateSettings params; |
zstein | 03adb7c | 2017-08-09 14:29:42 -0700 | [diff] [blame] | 570 | if (minBitrateBps != nil) { |
Danil Chapovalov | 196100e | 2018-06-21 10:17:24 +0200 | [diff] [blame] | 571 | params.min_bitrate_bps = absl::optional<int>(minBitrateBps.intValue); |
zstein | 03adb7c | 2017-08-09 14:29:42 -0700 | [diff] [blame] | 572 | } |
| 573 | if (currentBitrateBps != nil) { |
Niels Möller | 9ad1f6f | 2020-07-13 10:25:41 +0200 | [diff] [blame] | 574 | params.start_bitrate_bps = absl::optional<int>(currentBitrateBps.intValue); |
zstein | 03adb7c | 2017-08-09 14:29:42 -0700 | [diff] [blame] | 575 | } |
| 576 | if (maxBitrateBps != nil) { |
Danil Chapovalov | 196100e | 2018-06-21 10:17:24 +0200 | [diff] [blame] | 577 | params.max_bitrate_bps = absl::optional<int>(maxBitrateBps.intValue); |
zstein | 03adb7c | 2017-08-09 14:29:42 -0700 | [diff] [blame] | 578 | } |
| 579 | return _peerConnection->SetBitrate(params).ok(); |
| 580 | } |
| 581 | |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 582 | - (BOOL)startRtcEventLogWithFilePath:(NSString *)filePath |
| 583 | maxSizeInBytes:(int64_t)maxSizeInBytes { |
| 584 | RTC_DCHECK(filePath.length); |
| 585 | RTC_DCHECK_GT(maxSizeInBytes, 0); |
| 586 | RTC_DCHECK(!_hasStartedRtcEventLog); |
| 587 | if (_hasStartedRtcEventLog) { |
| 588 | RTCLogError(@"Event logging already started."); |
| 589 | return NO; |
| 590 | } |
Niels Möller | dec9f74 | 2019-06-03 15:25:20 +0200 | [diff] [blame] | 591 | FILE *f = fopen(filePath.UTF8String, "wb"); |
| 592 | if (!f) { |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 593 | RTCLogError(@"Error opening file: %@. Error: %d", filePath, errno); |
| 594 | return NO; |
| 595 | } |
Niels Möller | 695cf6a | 2019-05-13 12:27:23 +0200 | [diff] [blame] | 596 | // TODO(eladalon): It would be better to not allow negative values into PC. |
| 597 | const size_t max_size = (maxSizeInBytes < 0) ? webrtc::RtcEventLog::kUnlimitedOutput : |
| 598 | rtc::saturated_cast<size_t>(maxSizeInBytes); |
| 599 | |
| 600 | _hasStartedRtcEventLog = _peerConnection->StartRtcEventLog( |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 601 | std::make_unique<webrtc::RtcEventLogOutputFile>(f, max_size)); |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 602 | return _hasStartedRtcEventLog; |
| 603 | } |
| 604 | |
| 605 | - (void)stopRtcEventLog { |
| 606 | _peerConnection->StopRtcEventLog(); |
| 607 | _hasStartedRtcEventLog = NO; |
| 608 | } |
| 609 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 610 | - (RTC_OBJC_TYPE(RTCRtpSender) *)senderWithKind:(NSString *)kind streamId:(NSString *)streamId { |
skvlad | f3569c8 | 2016-04-29 15:30:16 -0700 | [diff] [blame] | 611 | std::string nativeKind = [NSString stdStringForString:kind]; |
| 612 | std::string nativeStreamId = [NSString stdStringForString:streamId]; |
| 613 | rtc::scoped_refptr<webrtc::RtpSenderInterface> nativeSender( |
| 614 | _peerConnection->CreateSender(nativeKind, nativeStreamId)); |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 615 | return nativeSender ? [[RTC_OBJC_TYPE(RTCRtpSender) alloc] initWithFactory:self.factory |
| 616 | nativeRtpSender:nativeSender] : |
| 617 | nil; |
skvlad | f3569c8 | 2016-04-29 15:30:16 -0700 | [diff] [blame] | 618 | } |
| 619 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 620 | - (NSArray<RTC_OBJC_TYPE(RTCRtpSender) *> *)senders { |
skvlad | 79b4b87 | 2016-04-08 17:28:55 -0700 | [diff] [blame] | 621 | std::vector<rtc::scoped_refptr<webrtc::RtpSenderInterface>> nativeSenders( |
| 622 | _peerConnection->GetSenders()); |
| 623 | NSMutableArray *senders = [[NSMutableArray alloc] init]; |
| 624 | for (const auto &nativeSender : nativeSenders) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 625 | RTC_OBJC_TYPE(RTCRtpSender) *sender = |
| 626 | [[RTC_OBJC_TYPE(RTCRtpSender) alloc] initWithFactory:self.factory |
| 627 | nativeRtpSender:nativeSender]; |
skvlad | 79b4b87 | 2016-04-08 17:28:55 -0700 | [diff] [blame] | 628 | [senders addObject:sender]; |
| 629 | } |
| 630 | return senders; |
| 631 | } |
| 632 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 633 | - (NSArray<RTC_OBJC_TYPE(RTCRtpReceiver) *> *)receivers { |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 634 | std::vector<rtc::scoped_refptr<webrtc::RtpReceiverInterface>> nativeReceivers( |
| 635 | _peerConnection->GetReceivers()); |
| 636 | NSMutableArray *receivers = [[NSMutableArray alloc] init]; |
| 637 | for (const auto &nativeReceiver : nativeReceivers) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 638 | RTC_OBJC_TYPE(RTCRtpReceiver) *receiver = |
| 639 | [[RTC_OBJC_TYPE(RTCRtpReceiver) alloc] initWithFactory:self.factory |
| 640 | nativeRtpReceiver:nativeReceiver]; |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 641 | [receivers addObject:receiver]; |
| 642 | } |
| 643 | return receivers; |
| 644 | } |
| 645 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 646 | - (NSArray<RTC_OBJC_TYPE(RTCRtpTransceiver) *> *)transceivers { |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 647 | std::vector<rtc::scoped_refptr<webrtc::RtpTransceiverInterface>> nativeTransceivers( |
| 648 | _peerConnection->GetTransceivers()); |
| 649 | NSMutableArray *transceivers = [[NSMutableArray alloc] init]; |
Mirko Bonadei | 739baf0 | 2019-01-27 17:29:42 +0100 | [diff] [blame] | 650 | for (const auto &nativeTransceiver : nativeTransceivers) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 651 | RTC_OBJC_TYPE(RTCRtpTransceiver) *transceiver = |
| 652 | [[RTC_OBJC_TYPE(RTCRtpTransceiver) alloc] initWithFactory:self.factory |
| 653 | nativeRtpTransceiver:nativeTransceiver]; |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 654 | [transceivers addObject:transceiver]; |
| 655 | } |
| 656 | return transceivers; |
| 657 | } |
| 658 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 659 | #pragma mark - Private |
| 660 | |
| 661 | + (webrtc::PeerConnectionInterface::SignalingState)nativeSignalingStateForState: |
| 662 | (RTCSignalingState)state { |
| 663 | switch (state) { |
| 664 | case RTCSignalingStateStable: |
| 665 | return webrtc::PeerConnectionInterface::kStable; |
| 666 | case RTCSignalingStateHaveLocalOffer: |
| 667 | return webrtc::PeerConnectionInterface::kHaveLocalOffer; |
| 668 | case RTCSignalingStateHaveLocalPrAnswer: |
| 669 | return webrtc::PeerConnectionInterface::kHaveLocalPrAnswer; |
| 670 | case RTCSignalingStateHaveRemoteOffer: |
| 671 | return webrtc::PeerConnectionInterface::kHaveRemoteOffer; |
| 672 | case RTCSignalingStateHaveRemotePrAnswer: |
| 673 | return webrtc::PeerConnectionInterface::kHaveRemotePrAnswer; |
| 674 | case RTCSignalingStateClosed: |
| 675 | return webrtc::PeerConnectionInterface::kClosed; |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | + (RTCSignalingState)signalingStateForNativeState: |
| 680 | (webrtc::PeerConnectionInterface::SignalingState)nativeState { |
| 681 | switch (nativeState) { |
| 682 | case webrtc::PeerConnectionInterface::kStable: |
| 683 | return RTCSignalingStateStable; |
| 684 | case webrtc::PeerConnectionInterface::kHaveLocalOffer: |
| 685 | return RTCSignalingStateHaveLocalOffer; |
| 686 | case webrtc::PeerConnectionInterface::kHaveLocalPrAnswer: |
| 687 | return RTCSignalingStateHaveLocalPrAnswer; |
| 688 | case webrtc::PeerConnectionInterface::kHaveRemoteOffer: |
| 689 | return RTCSignalingStateHaveRemoteOffer; |
| 690 | case webrtc::PeerConnectionInterface::kHaveRemotePrAnswer: |
| 691 | return RTCSignalingStateHaveRemotePrAnswer; |
| 692 | case webrtc::PeerConnectionInterface::kClosed: |
| 693 | return RTCSignalingStateClosed; |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | + (NSString *)stringForSignalingState:(RTCSignalingState)state { |
| 698 | switch (state) { |
| 699 | case RTCSignalingStateStable: |
| 700 | return @"STABLE"; |
| 701 | case RTCSignalingStateHaveLocalOffer: |
| 702 | return @"HAVE_LOCAL_OFFER"; |
| 703 | case RTCSignalingStateHaveLocalPrAnswer: |
| 704 | return @"HAVE_LOCAL_PRANSWER"; |
| 705 | case RTCSignalingStateHaveRemoteOffer: |
| 706 | return @"HAVE_REMOTE_OFFER"; |
| 707 | case RTCSignalingStateHaveRemotePrAnswer: |
| 708 | return @"HAVE_REMOTE_PRANSWER"; |
| 709 | case RTCSignalingStateClosed: |
| 710 | return @"CLOSED"; |
| 711 | } |
| 712 | } |
| 713 | |
Jonas Olsson | cfddbb7 | 2018-11-15 16:52:45 +0100 | [diff] [blame] | 714 | + (webrtc::PeerConnectionInterface::PeerConnectionState)nativeConnectionStateForState: |
| 715 | (RTCPeerConnectionState)state { |
| 716 | switch (state) { |
| 717 | case RTCPeerConnectionStateNew: |
| 718 | return webrtc::PeerConnectionInterface::PeerConnectionState::kNew; |
| 719 | case RTCPeerConnectionStateConnecting: |
| 720 | return webrtc::PeerConnectionInterface::PeerConnectionState::kConnecting; |
| 721 | case RTCPeerConnectionStateConnected: |
| 722 | return webrtc::PeerConnectionInterface::PeerConnectionState::kConnected; |
| 723 | case RTCPeerConnectionStateFailed: |
| 724 | return webrtc::PeerConnectionInterface::PeerConnectionState::kFailed; |
| 725 | case RTCPeerConnectionStateDisconnected: |
| 726 | return webrtc::PeerConnectionInterface::PeerConnectionState::kDisconnected; |
| 727 | case RTCPeerConnectionStateClosed: |
| 728 | return webrtc::PeerConnectionInterface::PeerConnectionState::kClosed; |
| 729 | } |
| 730 | } |
| 731 | |
| 732 | + (RTCPeerConnectionState)connectionStateForNativeState: |
| 733 | (webrtc::PeerConnectionInterface::PeerConnectionState)nativeState { |
| 734 | switch (nativeState) { |
| 735 | case webrtc::PeerConnectionInterface::PeerConnectionState::kNew: |
| 736 | return RTCPeerConnectionStateNew; |
| 737 | case webrtc::PeerConnectionInterface::PeerConnectionState::kConnecting: |
| 738 | return RTCPeerConnectionStateConnecting; |
| 739 | case webrtc::PeerConnectionInterface::PeerConnectionState::kConnected: |
| 740 | return RTCPeerConnectionStateConnected; |
| 741 | case webrtc::PeerConnectionInterface::PeerConnectionState::kFailed: |
| 742 | return RTCPeerConnectionStateFailed; |
| 743 | case webrtc::PeerConnectionInterface::PeerConnectionState::kDisconnected: |
| 744 | return RTCPeerConnectionStateDisconnected; |
| 745 | case webrtc::PeerConnectionInterface::PeerConnectionState::kClosed: |
| 746 | return RTCPeerConnectionStateClosed; |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | + (NSString *)stringForConnectionState:(RTCPeerConnectionState)state { |
| 751 | switch (state) { |
| 752 | case RTCPeerConnectionStateNew: |
| 753 | return @"NEW"; |
| 754 | case RTCPeerConnectionStateConnecting: |
| 755 | return @"CONNECTING"; |
| 756 | case RTCPeerConnectionStateConnected: |
| 757 | return @"CONNECTED"; |
| 758 | case RTCPeerConnectionStateFailed: |
| 759 | return @"FAILED"; |
| 760 | case RTCPeerConnectionStateDisconnected: |
| 761 | return @"DISCONNECTED"; |
| 762 | case RTCPeerConnectionStateClosed: |
| 763 | return @"CLOSED"; |
| 764 | } |
| 765 | } |
| 766 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 767 | + (webrtc::PeerConnectionInterface::IceConnectionState) |
| 768 | nativeIceConnectionStateForState:(RTCIceConnectionState)state { |
| 769 | switch (state) { |
| 770 | case RTCIceConnectionStateNew: |
| 771 | return webrtc::PeerConnectionInterface::kIceConnectionNew; |
| 772 | case RTCIceConnectionStateChecking: |
| 773 | return webrtc::PeerConnectionInterface::kIceConnectionChecking; |
| 774 | case RTCIceConnectionStateConnected: |
| 775 | return webrtc::PeerConnectionInterface::kIceConnectionConnected; |
| 776 | case RTCIceConnectionStateCompleted: |
| 777 | return webrtc::PeerConnectionInterface::kIceConnectionCompleted; |
| 778 | case RTCIceConnectionStateFailed: |
| 779 | return webrtc::PeerConnectionInterface::kIceConnectionFailed; |
| 780 | case RTCIceConnectionStateDisconnected: |
| 781 | return webrtc::PeerConnectionInterface::kIceConnectionDisconnected; |
| 782 | case RTCIceConnectionStateClosed: |
| 783 | return webrtc::PeerConnectionInterface::kIceConnectionClosed; |
hjon | 8bbbf2c | 2016-03-14 13:15:44 -0700 | [diff] [blame] | 784 | case RTCIceConnectionStateCount: |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 785 | return webrtc::PeerConnectionInterface::kIceConnectionMax; |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | + (RTCIceConnectionState)iceConnectionStateForNativeState: |
| 790 | (webrtc::PeerConnectionInterface::IceConnectionState)nativeState { |
| 791 | switch (nativeState) { |
| 792 | case webrtc::PeerConnectionInterface::kIceConnectionNew: |
| 793 | return RTCIceConnectionStateNew; |
| 794 | case webrtc::PeerConnectionInterface::kIceConnectionChecking: |
| 795 | return RTCIceConnectionStateChecking; |
| 796 | case webrtc::PeerConnectionInterface::kIceConnectionConnected: |
| 797 | return RTCIceConnectionStateConnected; |
| 798 | case webrtc::PeerConnectionInterface::kIceConnectionCompleted: |
| 799 | return RTCIceConnectionStateCompleted; |
| 800 | case webrtc::PeerConnectionInterface::kIceConnectionFailed: |
| 801 | return RTCIceConnectionStateFailed; |
| 802 | case webrtc::PeerConnectionInterface::kIceConnectionDisconnected: |
| 803 | return RTCIceConnectionStateDisconnected; |
| 804 | case webrtc::PeerConnectionInterface::kIceConnectionClosed: |
| 805 | return RTCIceConnectionStateClosed; |
| 806 | case webrtc::PeerConnectionInterface::kIceConnectionMax: |
hjon | 8bbbf2c | 2016-03-14 13:15:44 -0700 | [diff] [blame] | 807 | return RTCIceConnectionStateCount; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 808 | } |
| 809 | } |
| 810 | |
| 811 | + (NSString *)stringForIceConnectionState:(RTCIceConnectionState)state { |
| 812 | switch (state) { |
| 813 | case RTCIceConnectionStateNew: |
| 814 | return @"NEW"; |
| 815 | case RTCIceConnectionStateChecking: |
| 816 | return @"CHECKING"; |
| 817 | case RTCIceConnectionStateConnected: |
| 818 | return @"CONNECTED"; |
| 819 | case RTCIceConnectionStateCompleted: |
| 820 | return @"COMPLETED"; |
| 821 | case RTCIceConnectionStateFailed: |
| 822 | return @"FAILED"; |
| 823 | case RTCIceConnectionStateDisconnected: |
| 824 | return @"DISCONNECTED"; |
| 825 | case RTCIceConnectionStateClosed: |
| 826 | return @"CLOSED"; |
hjon | 8bbbf2c | 2016-03-14 13:15:44 -0700 | [diff] [blame] | 827 | case RTCIceConnectionStateCount: |
| 828 | return @"COUNT"; |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 829 | } |
| 830 | } |
| 831 | |
| 832 | + (webrtc::PeerConnectionInterface::IceGatheringState) |
| 833 | nativeIceGatheringStateForState:(RTCIceGatheringState)state { |
| 834 | switch (state) { |
| 835 | case RTCIceGatheringStateNew: |
| 836 | return webrtc::PeerConnectionInterface::kIceGatheringNew; |
| 837 | case RTCIceGatheringStateGathering: |
| 838 | return webrtc::PeerConnectionInterface::kIceGatheringGathering; |
| 839 | case RTCIceGatheringStateComplete: |
| 840 | return webrtc::PeerConnectionInterface::kIceGatheringComplete; |
| 841 | } |
| 842 | } |
| 843 | |
| 844 | + (RTCIceGatheringState)iceGatheringStateForNativeState: |
| 845 | (webrtc::PeerConnectionInterface::IceGatheringState)nativeState { |
| 846 | switch (nativeState) { |
| 847 | case webrtc::PeerConnectionInterface::kIceGatheringNew: |
| 848 | return RTCIceGatheringStateNew; |
| 849 | case webrtc::PeerConnectionInterface::kIceGatheringGathering: |
| 850 | return RTCIceGatheringStateGathering; |
| 851 | case webrtc::PeerConnectionInterface::kIceGatheringComplete: |
| 852 | return RTCIceGatheringStateComplete; |
| 853 | } |
| 854 | } |
| 855 | |
| 856 | + (NSString *)stringForIceGatheringState:(RTCIceGatheringState)state { |
| 857 | switch (state) { |
| 858 | case RTCIceGatheringStateNew: |
| 859 | return @"NEW"; |
| 860 | case RTCIceGatheringStateGathering: |
| 861 | return @"GATHERING"; |
| 862 | case RTCIceGatheringStateComplete: |
| 863 | return @"COMPLETE"; |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | + (webrtc::PeerConnectionInterface::StatsOutputLevel) |
| 868 | nativeStatsOutputLevelForLevel:(RTCStatsOutputLevel)level { |
| 869 | switch (level) { |
| 870 | case RTCStatsOutputLevelStandard: |
| 871 | return webrtc::PeerConnectionInterface::kStatsOutputLevelStandard; |
| 872 | case RTCStatsOutputLevelDebug: |
| 873 | return webrtc::PeerConnectionInterface::kStatsOutputLevelDebug; |
| 874 | } |
| 875 | } |
| 876 | |
hjon | f396f60 | 2016-02-11 16:19:06 -0800 | [diff] [blame] | 877 | - (rtc::scoped_refptr<webrtc::PeerConnectionInterface>)nativePeerConnection { |
| 878 | return _peerConnection; |
| 879 | } |
| 880 | |
| 881 | @end |