hjon | 6d49a8e | 2016-01-26 13:06:42 -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 "RTCConfiguration+Private.h" |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 12 | |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 13 | #include <memory> |
| 14 | |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame] | 15 | #import "RTCCertificate.h" |
Zeke Chin | ef1140e | 2017-10-27 15:42:08 -0700 | [diff] [blame] | 16 | #import "RTCConfiguration+Native.h" |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 17 | #import "RTCIceServer+Private.h" |
Anders Carlsson | 7bca8ca | 2018-08-30 09:30:29 +0200 | [diff] [blame] | 18 | #import "base/RTCLogging.h" |
tkchin | ab8f82f | 2016-01-27 17:50:11 -0800 | [diff] [blame] | 19 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 20 | #include "rtc_base/rtc_certificate_generator.h" |
| 21 | #include "rtc_base/ssl_identity.h" |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 22 | |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 23 | @implementation RTC_OBJC_TYPE (RTCConfiguration) |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 24 | |
Taylor Brandstetter | 21c8032 | 2020-03-24 15:41:19 -0700 | [diff] [blame] | 25 | @synthesize enableDscp = _enableDscp; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 26 | @synthesize iceServers = _iceServers; |
Michael Iedema | ccee56b | 2018-07-05 15:28:24 +0200 | [diff] [blame] | 27 | @synthesize certificate = _certificate; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 28 | @synthesize iceTransportPolicy = _iceTransportPolicy; |
| 29 | @synthesize bundlePolicy = _bundlePolicy; |
| 30 | @synthesize rtcpMuxPolicy = _rtcpMuxPolicy; |
| 31 | @synthesize tcpCandidatePolicy = _tcpCandidatePolicy; |
Honghai Zhang | 46007ae | 2016-06-03 16:31:32 -0700 | [diff] [blame] | 32 | @synthesize candidateNetworkPolicy = _candidateNetworkPolicy; |
Honghai Zhang | 3108fc9 | 2016-05-11 10:10:39 -0700 | [diff] [blame] | 33 | @synthesize continualGatheringPolicy = _continualGatheringPolicy; |
Uladzislau Susha | bf0d0c1 | 2018-11-05 12:48:35 +0300 | [diff] [blame] | 34 | @synthesize disableIPV6 = _disableIPV6; |
| 35 | @synthesize disableIPV6OnWiFi = _disableIPV6OnWiFi; |
deadbeef | 2059bb3 | 2017-07-26 18:25:43 -0700 | [diff] [blame] | 36 | @synthesize maxIPv6Networks = _maxIPv6Networks; |
Daniel Lazarenko | 2870b0a | 2018-01-25 10:30:22 +0100 | [diff] [blame] | 37 | @synthesize disableLinkLocalNetworks = _disableLinkLocalNetworks; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 38 | @synthesize audioJitterBufferMaxPackets = _audioJitterBufferMaxPackets; |
haysc | c9f9500 | 2016-12-05 14:24:32 -0800 | [diff] [blame] | 39 | @synthesize audioJitterBufferFastAccelerate = _audioJitterBufferFastAccelerate; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 40 | @synthesize iceConnectionReceivingTimeout = _iceConnectionReceivingTimeout; |
| 41 | @synthesize iceBackupCandidatePairPingInterval = |
| 42 | _iceBackupCandidatePairPingInterval; |
tkchin | ab8f82f | 2016-01-27 17:50:11 -0800 | [diff] [blame] | 43 | @synthesize keyType = _keyType; |
deadbeef | be0c96f | 2016-05-18 16:20:14 -0700 | [diff] [blame] | 44 | @synthesize iceCandidatePoolSize = _iceCandidatePoolSize; |
honghaiz | af6b6e0 | 2016-07-11 15:09:26 -0700 | [diff] [blame] | 45 | @synthesize shouldPruneTurnPorts = _shouldPruneTurnPorts; |
| 46 | @synthesize shouldPresumeWritableWhenFullyRelayed = |
| 47 | _shouldPresumeWritableWhenFullyRelayed; |
Qingsi Wang | 1fe119f | 2019-05-31 16:55:33 -0700 | [diff] [blame] | 48 | @synthesize shouldSurfaceIceCandidatesOnIceTransportTypeChanged = |
| 49 | _shouldSurfaceIceCandidatesOnIceTransportTypeChanged; |
skvlad | a5d94ff | 2017-02-02 13:02:30 -0800 | [diff] [blame] | 50 | @synthesize iceCheckMinInterval = _iceCheckMinInterval; |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 51 | @synthesize sdpSemantics = _sdpSemantics; |
Zeke Chin | ef1140e | 2017-10-27 15:42:08 -0700 | [diff] [blame] | 52 | @synthesize turnCustomizer = _turnCustomizer; |
Zhi Huang | b57e169 | 2018-06-12 11:41:11 -0700 | [diff] [blame] | 53 | @synthesize activeResetSrtpParams = _activeResetSrtpParams; |
philipel | 3eb84f0 | 2019-11-11 12:57:44 +0100 | [diff] [blame] | 54 | @synthesize allowCodecSwitching = _allowCodecSwitching; |
Benjamin Wright | 8c27cca | 2018-10-25 10:16:44 -0700 | [diff] [blame] | 55 | @synthesize cryptoOptions = _cryptoOptions; |
Jiawei Ou | b1e4775 | 2018-11-13 23:48:19 -0800 | [diff] [blame] | 56 | @synthesize rtcpAudioReportIntervalMs = _rtcpAudioReportIntervalMs; |
| 57 | @synthesize rtcpVideoReportIntervalMs = _rtcpVideoReportIntervalMs; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 58 | |
| 59 | - (instancetype)init { |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 60 | // Copy defaults. |
Yuriy Pavlyshak | 8cec4fb | 2018-09-07 16:43:31 +0200 | [diff] [blame] | 61 | webrtc::PeerConnectionInterface::RTCConfiguration config; |
jtteh | 465faf0 | 2017-04-04 14:00:16 -0700 | [diff] [blame] | 62 | return [self initWithNativeConfiguration:config]; |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | - (instancetype)initWithNativeConfiguration: |
jtteh | 465faf0 | 2017-04-04 14:00:16 -0700 | [diff] [blame] | 66 | (const webrtc::PeerConnectionInterface::RTCConfiguration &)config { |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 67 | if (self = [super init]) { |
Taylor Brandstetter | 21c8032 | 2020-03-24 15:41:19 -0700 | [diff] [blame] | 68 | _enableDscp = config.dscp(); |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 69 | NSMutableArray *iceServers = [NSMutableArray array]; |
jtteh | 465faf0 | 2017-04-04 14:00:16 -0700 | [diff] [blame] | 70 | for (const webrtc::PeerConnectionInterface::IceServer& server : config.servers) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 71 | RTC_OBJC_TYPE(RTCIceServer) *iceServer = |
| 72 | [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithNativeServer:server]; |
jtteh | 4eeb537 | 2017-04-03 15:06:37 -0700 | [diff] [blame] | 73 | [iceServers addObject:iceServer]; |
| 74 | } |
| 75 | _iceServers = iceServers; |
Michael Iedema | ccee56b | 2018-07-05 15:28:24 +0200 | [diff] [blame] | 76 | if (!config.certificates.empty()) { |
| 77 | rtc::scoped_refptr<rtc::RTCCertificate> native_cert; |
| 78 | native_cert = config.certificates[0]; |
| 79 | rtc::RTCCertificatePEM native_pem = native_cert->ToPEM(); |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 80 | _certificate = [[RTC_OBJC_TYPE(RTCCertificate) alloc] |
| 81 | initWithPrivateKey:@(native_pem.private_key().c_str()) |
| 82 | certificate:@(native_pem.certificate().c_str())]; |
Michael Iedema | ccee56b | 2018-07-05 15:28:24 +0200 | [diff] [blame] | 83 | } |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 84 | _iceTransportPolicy = |
jtteh | 465faf0 | 2017-04-04 14:00:16 -0700 | [diff] [blame] | 85 | [[self class] transportPolicyForTransportsType:config.type]; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 86 | _bundlePolicy = |
jtteh | 465faf0 | 2017-04-04 14:00:16 -0700 | [diff] [blame] | 87 | [[self class] bundlePolicyForNativePolicy:config.bundle_policy]; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 88 | _rtcpMuxPolicy = |
jtteh | 465faf0 | 2017-04-04 14:00:16 -0700 | [diff] [blame] | 89 | [[self class] rtcpMuxPolicyForNativePolicy:config.rtcp_mux_policy]; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 90 | _tcpCandidatePolicy = [[self class] tcpCandidatePolicyForNativePolicy: |
jtteh | 465faf0 | 2017-04-04 14:00:16 -0700 | [diff] [blame] | 91 | config.tcp_candidate_policy]; |
Honghai Zhang | 46007ae | 2016-06-03 16:31:32 -0700 | [diff] [blame] | 92 | _candidateNetworkPolicy = [[self class] |
jtteh | 465faf0 | 2017-04-04 14:00:16 -0700 | [diff] [blame] | 93 | candidateNetworkPolicyForNativePolicy:config.candidate_network_policy]; |
Honghai Zhang | 3108fc9 | 2016-05-11 10:10:39 -0700 | [diff] [blame] | 94 | webrtc::PeerConnectionInterface::ContinualGatheringPolicy nativePolicy = |
jtteh | 465faf0 | 2017-04-04 14:00:16 -0700 | [diff] [blame] | 95 | config.continual_gathering_policy; |
Honghai Zhang | 3108fc9 | 2016-05-11 10:10:39 -0700 | [diff] [blame] | 96 | _continualGatheringPolicy = |
| 97 | [[self class] continualGatheringPolicyForNativePolicy:nativePolicy]; |
Uladzislau Susha | bf0d0c1 | 2018-11-05 12:48:35 +0300 | [diff] [blame] | 98 | _disableIPV6 = config.disable_ipv6; |
| 99 | _disableIPV6OnWiFi = config.disable_ipv6_on_wifi; |
deadbeef | 2059bb3 | 2017-07-26 18:25:43 -0700 | [diff] [blame] | 100 | _maxIPv6Networks = config.max_ipv6_networks; |
Daniel Lazarenko | 2870b0a | 2018-01-25 10:30:22 +0100 | [diff] [blame] | 101 | _disableLinkLocalNetworks = config.disable_link_local_networks; |
jtteh | 465faf0 | 2017-04-04 14:00:16 -0700 | [diff] [blame] | 102 | _audioJitterBufferMaxPackets = config.audio_jitter_buffer_max_packets; |
| 103 | _audioJitterBufferFastAccelerate = config.audio_jitter_buffer_fast_accelerate; |
| 104 | _iceConnectionReceivingTimeout = config.ice_connection_receiving_timeout; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 105 | _iceBackupCandidatePairPingInterval = |
jtteh | 465faf0 | 2017-04-04 14:00:16 -0700 | [diff] [blame] | 106 | config.ice_backup_candidate_pair_ping_interval; |
tkchin | ab8f82f | 2016-01-27 17:50:11 -0800 | [diff] [blame] | 107 | _keyType = RTCEncryptionKeyTypeECDSA; |
jtteh | 465faf0 | 2017-04-04 14:00:16 -0700 | [diff] [blame] | 108 | _iceCandidatePoolSize = config.ice_candidate_pool_size; |
| 109 | _shouldPruneTurnPorts = config.prune_turn_ports; |
honghaiz | af6b6e0 | 2016-07-11 15:09:26 -0700 | [diff] [blame] | 110 | _shouldPresumeWritableWhenFullyRelayed = |
jtteh | 465faf0 | 2017-04-04 14:00:16 -0700 | [diff] [blame] | 111 | config.presume_writable_when_fully_relayed; |
Qingsi Wang | 1fe119f | 2019-05-31 16:55:33 -0700 | [diff] [blame] | 112 | _shouldSurfaceIceCandidatesOnIceTransportTypeChanged = |
| 113 | config.surface_ice_candidates_on_ice_transport_type_changed; |
jtteh | 465faf0 | 2017-04-04 14:00:16 -0700 | [diff] [blame] | 114 | if (config.ice_check_min_interval) { |
skvlad | a5d94ff | 2017-02-02 13:02:30 -0800 | [diff] [blame] | 115 | _iceCheckMinInterval = |
jtteh | 465faf0 | 2017-04-04 14:00:16 -0700 | [diff] [blame] | 116 | [NSNumber numberWithInt:*config.ice_check_min_interval]; |
skvlad | a5d94ff | 2017-02-02 13:02:30 -0800 | [diff] [blame] | 117 | } |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 118 | _sdpSemantics = [[self class] sdpSemanticsForNativeSdpSemantics:config.sdp_semantics]; |
Zeke Chin | ef1140e | 2017-10-27 15:42:08 -0700 | [diff] [blame] | 119 | _turnCustomizer = config.turn_customizer; |
Zhi Huang | b57e169 | 2018-06-12 11:41:11 -0700 | [diff] [blame] | 120 | _activeResetSrtpParams = config.active_reset_srtp_params; |
Benjamin Wright | 8c27cca | 2018-10-25 10:16:44 -0700 | [diff] [blame] | 121 | if (config.crypto_options) { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 122 | _cryptoOptions = [[RTC_OBJC_TYPE(RTCCryptoOptions) alloc] |
Benjamin Wright | 8c27cca | 2018-10-25 10:16:44 -0700 | [diff] [blame] | 123 | initWithSrtpEnableGcmCryptoSuites:config.crypto_options->srtp |
| 124 | .enable_gcm_crypto_suites |
| 125 | srtpEnableAes128Sha1_32CryptoCipher:config.crypto_options->srtp |
| 126 | .enable_aes128_sha1_32_crypto_cipher |
| 127 | srtpEnableEncryptedRtpHeaderExtensions:config.crypto_options->srtp |
| 128 | .enable_encrypted_rtp_header_extensions |
| 129 | sframeRequireFrameEncryption:config.crypto_options->sframe |
| 130 | .require_frame_encryption]; |
| 131 | } |
Jiawei Ou | b1e4775 | 2018-11-13 23:48:19 -0800 | [diff] [blame] | 132 | _rtcpAudioReportIntervalMs = config.audio_rtcp_report_interval_ms(); |
| 133 | _rtcpVideoReportIntervalMs = config.video_rtcp_report_interval_ms(); |
philipel | 3eb84f0 | 2019-11-11 12:57:44 +0100 | [diff] [blame] | 134 | _allowCodecSwitching = config.allow_codec_switching.value_or(false); |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 135 | } |
| 136 | return self; |
| 137 | } |
| 138 | |
| 139 | - (NSString *)description { |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 140 | static NSString *formatString = @"RTC_OBJC_TYPE(RTCConfiguration): " |
Uladzislau Susha | bf0d0c1 | 2018-11-05 12:48:35 +0300 | [diff] [blame] | 141 | @"{\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%d\n%d\n%d\n%d\n%d\n%d\n" |
Niels Möller | 938bc33 | 2020-06-10 17:36:17 +0200 | [diff] [blame] | 142 | @"%d\n%@\n%d\n%d\n%d\n%d\n%d\n%@\n}\n"; |
Daniel Lazarenko | 2870b0a | 2018-01-25 10:30:22 +0100 | [diff] [blame] | 143 | |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 144 | return [NSString |
| 145 | stringWithFormat:formatString, |
| 146 | _iceServers, |
| 147 | [[self class] stringForTransportPolicy:_iceTransportPolicy], |
| 148 | [[self class] stringForBundlePolicy:_bundlePolicy], |
| 149 | [[self class] stringForRtcpMuxPolicy:_rtcpMuxPolicy], |
| 150 | [[self class] stringForTcpCandidatePolicy:_tcpCandidatePolicy], |
| 151 | [[self class] stringForCandidateNetworkPolicy:_candidateNetworkPolicy], |
| 152 | [[self class] stringForContinualGatheringPolicy:_continualGatheringPolicy], |
| 153 | [[self class] stringForSdpSemantics:_sdpSemantics], |
| 154 | _audioJitterBufferMaxPackets, |
| 155 | _audioJitterBufferFastAccelerate, |
| 156 | _iceConnectionReceivingTimeout, |
| 157 | _iceBackupCandidatePairPingInterval, |
| 158 | _iceCandidatePoolSize, |
| 159 | _shouldPruneTurnPorts, |
| 160 | _shouldPresumeWritableWhenFullyRelayed, |
Qingsi Wang | 1fe119f | 2019-05-31 16:55:33 -0700 | [diff] [blame] | 161 | _shouldSurfaceIceCandidatesOnIceTransportTypeChanged, |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 162 | _iceCheckMinInterval, |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 163 | _disableLinkLocalNetworks, |
Uladzislau Susha | bf0d0c1 | 2018-11-05 12:48:35 +0300 | [diff] [blame] | 164 | _disableIPV6, |
| 165 | _disableIPV6OnWiFi, |
Zhi Huang | b57e169 | 2018-06-12 11:41:11 -0700 | [diff] [blame] | 166 | _maxIPv6Networks, |
Piotr (Peter) Slatala | e0c2e97 | 2018-10-08 09:43:21 -0700 | [diff] [blame] | 167 | _activeResetSrtpParams, |
Taylor Brandstetter | 21c8032 | 2020-03-24 15:41:19 -0700 | [diff] [blame] | 168 | _enableDscp]; |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | #pragma mark - Private |
| 172 | |
hbos | a73ca56 | 2016-05-17 03:28:58 -0700 | [diff] [blame] | 173 | - (webrtc::PeerConnectionInterface::RTCConfiguration *) |
| 174 | createNativeConfiguration { |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 175 | std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> |
Honghai Zhang | f7ddc06 | 2016-09-01 15:34:01 -0700 | [diff] [blame] | 176 | nativeConfig(new webrtc::PeerConnectionInterface::RTCConfiguration( |
| 177 | webrtc::PeerConnectionInterface::RTCConfigurationType::kAggressive)); |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 178 | |
Taylor Brandstetter | 21c8032 | 2020-03-24 15:41:19 -0700 | [diff] [blame] | 179 | nativeConfig->set_dscp(_enableDscp); |
Mirko Bonadei | a81e9c8 | 2020-05-04 16:14:32 +0200 | [diff] [blame] | 180 | for (RTC_OBJC_TYPE(RTCIceServer) * iceServer in _iceServers) { |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 181 | nativeConfig->servers.push_back(iceServer.nativeServer); |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 182 | } |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 183 | nativeConfig->type = |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 184 | [[self class] nativeTransportsTypeForTransportPolicy:_iceTransportPolicy]; |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 185 | nativeConfig->bundle_policy = |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 186 | [[self class] nativeBundlePolicyForPolicy:_bundlePolicy]; |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 187 | nativeConfig->rtcp_mux_policy = |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 188 | [[self class] nativeRtcpMuxPolicyForPolicy:_rtcpMuxPolicy]; |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 189 | nativeConfig->tcp_candidate_policy = |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 190 | [[self class] nativeTcpCandidatePolicyForPolicy:_tcpCandidatePolicy]; |
Honghai Zhang | 46007ae | 2016-06-03 16:31:32 -0700 | [diff] [blame] | 191 | nativeConfig->candidate_network_policy = [[self class] |
| 192 | nativeCandidateNetworkPolicyForPolicy:_candidateNetworkPolicy]; |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 193 | nativeConfig->continual_gathering_policy = [[self class] |
Honghai Zhang | 3108fc9 | 2016-05-11 10:10:39 -0700 | [diff] [blame] | 194 | nativeContinualGatheringPolicyForPolicy:_continualGatheringPolicy]; |
Uladzislau Susha | bf0d0c1 | 2018-11-05 12:48:35 +0300 | [diff] [blame] | 195 | nativeConfig->disable_ipv6 = _disableIPV6; |
| 196 | nativeConfig->disable_ipv6_on_wifi = _disableIPV6OnWiFi; |
deadbeef | 2059bb3 | 2017-07-26 18:25:43 -0700 | [diff] [blame] | 197 | nativeConfig->max_ipv6_networks = _maxIPv6Networks; |
Daniel Lazarenko | 2870b0a | 2018-01-25 10:30:22 +0100 | [diff] [blame] | 198 | nativeConfig->disable_link_local_networks = _disableLinkLocalNetworks; |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 199 | nativeConfig->audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets; |
haysc | c9f9500 | 2016-12-05 14:24:32 -0800 | [diff] [blame] | 200 | nativeConfig->audio_jitter_buffer_fast_accelerate = |
| 201 | _audioJitterBufferFastAccelerate ? true : false; |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 202 | nativeConfig->ice_connection_receiving_timeout = |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 203 | _iceConnectionReceivingTimeout; |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 204 | nativeConfig->ice_backup_candidate_pair_ping_interval = |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 205 | _iceBackupCandidatePairPingInterval; |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 206 | rtc::KeyType keyType = |
| 207 | [[self class] nativeEncryptionKeyTypeForKeyType:_keyType]; |
Michael Iedema | ccee56b | 2018-07-05 15:28:24 +0200 | [diff] [blame] | 208 | if (_certificate != nullptr) { |
| 209 | // if offered a pemcert use it... |
| 210 | RTC_LOG(LS_INFO) << "Have configured cert - using it."; |
| 211 | std::string pem_private_key = [[_certificate private_key] UTF8String]; |
| 212 | std::string pem_certificate = [[_certificate certificate] UTF8String]; |
| 213 | rtc::RTCCertificatePEM pem = rtc::RTCCertificatePEM(pem_private_key, pem_certificate); |
| 214 | rtc::scoped_refptr<rtc::RTCCertificate> certificate = rtc::RTCCertificate::FromPEM(pem); |
| 215 | RTC_LOG(LS_INFO) << "Created cert from PEM strings."; |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 216 | if (!certificate) { |
Michael Iedema | ccee56b | 2018-07-05 15:28:24 +0200 | [diff] [blame] | 217 | RTC_LOG(LS_ERROR) << "Failed to generate certificate from PEM."; |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 218 | return nullptr; |
tkchin | ab8f82f | 2016-01-27 17:50:11 -0800 | [diff] [blame] | 219 | } |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 220 | nativeConfig->certificates.push_back(certificate); |
Michael Iedema | ccee56b | 2018-07-05 15:28:24 +0200 | [diff] [blame] | 221 | } else { |
| 222 | RTC_LOG(LS_INFO) << "Don't have configured cert."; |
| 223 | // Generate non-default certificate. |
| 224 | if (keyType != rtc::KT_DEFAULT) { |
| 225 | rtc::scoped_refptr<rtc::RTCCertificate> certificate = |
| 226 | rtc::RTCCertificateGenerator::GenerateCertificate(rtc::KeyParams(keyType), |
| 227 | absl::optional<uint64_t>()); |
| 228 | if (!certificate) { |
| 229 | RTCLogError(@"Failed to generate certificate."); |
| 230 | return nullptr; |
| 231 | } |
| 232 | nativeConfig->certificates.push_back(certificate); |
| 233 | } |
tkchin | ab8f82f | 2016-01-27 17:50:11 -0800 | [diff] [blame] | 234 | } |
deadbeef | be0c96f | 2016-05-18 16:20:14 -0700 | [diff] [blame] | 235 | nativeConfig->ice_candidate_pool_size = _iceCandidatePoolSize; |
honghaiz | af6b6e0 | 2016-07-11 15:09:26 -0700 | [diff] [blame] | 236 | nativeConfig->prune_turn_ports = _shouldPruneTurnPorts ? true : false; |
Taylor Brandstetter | e985111 | 2016-07-01 11:11:13 -0700 | [diff] [blame] | 237 | nativeConfig->presume_writable_when_fully_relayed = |
honghaiz | af6b6e0 | 2016-07-11 15:09:26 -0700 | [diff] [blame] | 238 | _shouldPresumeWritableWhenFullyRelayed ? true : false; |
Qingsi Wang | 1fe119f | 2019-05-31 16:55:33 -0700 | [diff] [blame] | 239 | nativeConfig->surface_ice_candidates_on_ice_transport_type_changed = |
| 240 | _shouldSurfaceIceCandidatesOnIceTransportTypeChanged ? true : false; |
skvlad | a5d94ff | 2017-02-02 13:02:30 -0800 | [diff] [blame] | 241 | if (_iceCheckMinInterval != nil) { |
Danil Chapovalov | 196100e | 2018-06-21 10:17:24 +0200 | [diff] [blame] | 242 | nativeConfig->ice_check_min_interval = absl::optional<int>(_iceCheckMinInterval.intValue); |
skvlad | a5d94ff | 2017-02-02 13:02:30 -0800 | [diff] [blame] | 243 | } |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 244 | nativeConfig->sdp_semantics = [[self class] nativeSdpSemanticsForSdpSemantics:_sdpSemantics]; |
Zeke Chin | ef1140e | 2017-10-27 15:42:08 -0700 | [diff] [blame] | 245 | if (_turnCustomizer) { |
| 246 | nativeConfig->turn_customizer = _turnCustomizer; |
| 247 | } |
Zhi Huang | b57e169 | 2018-06-12 11:41:11 -0700 | [diff] [blame] | 248 | nativeConfig->active_reset_srtp_params = _activeResetSrtpParams ? true : false; |
Benjamin Wright | 8c27cca | 2018-10-25 10:16:44 -0700 | [diff] [blame] | 249 | if (_cryptoOptions) { |
| 250 | webrtc::CryptoOptions nativeCryptoOptions; |
| 251 | nativeCryptoOptions.srtp.enable_gcm_crypto_suites = |
| 252 | _cryptoOptions.srtpEnableGcmCryptoSuites ? true : false; |
| 253 | nativeCryptoOptions.srtp.enable_aes128_sha1_32_crypto_cipher = |
| 254 | _cryptoOptions.srtpEnableAes128Sha1_32CryptoCipher ? true : false; |
| 255 | nativeCryptoOptions.srtp.enable_encrypted_rtp_header_extensions = |
| 256 | _cryptoOptions.srtpEnableEncryptedRtpHeaderExtensions ? true : false; |
| 257 | nativeCryptoOptions.sframe.require_frame_encryption = |
| 258 | _cryptoOptions.sframeRequireFrameEncryption ? true : false; |
| 259 | nativeConfig->crypto_options = absl::optional<webrtc::CryptoOptions>(nativeCryptoOptions); |
| 260 | } |
Jiawei Ou | b1e4775 | 2018-11-13 23:48:19 -0800 | [diff] [blame] | 261 | nativeConfig->set_audio_rtcp_report_interval_ms(_rtcpAudioReportIntervalMs); |
| 262 | nativeConfig->set_video_rtcp_report_interval_ms(_rtcpVideoReportIntervalMs); |
philipel | 3eb84f0 | 2019-11-11 12:57:44 +0100 | [diff] [blame] | 263 | nativeConfig->allow_codec_switching = _allowCodecSwitching; |
Henrik Boström | e06c2dd | 2016-05-13 13:50:38 +0200 | [diff] [blame] | 264 | return nativeConfig.release(); |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 265 | } |
| 266 | |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 267 | + (webrtc::PeerConnectionInterface::IceTransportsType) |
| 268 | nativeTransportsTypeForTransportPolicy:(RTCIceTransportPolicy)policy { |
| 269 | switch (policy) { |
| 270 | case RTCIceTransportPolicyNone: |
| 271 | return webrtc::PeerConnectionInterface::kNone; |
| 272 | case RTCIceTransportPolicyRelay: |
| 273 | return webrtc::PeerConnectionInterface::kRelay; |
| 274 | case RTCIceTransportPolicyNoHost: |
| 275 | return webrtc::PeerConnectionInterface::kNoHost; |
| 276 | case RTCIceTransportPolicyAll: |
| 277 | return webrtc::PeerConnectionInterface::kAll; |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | + (RTCIceTransportPolicy)transportPolicyForTransportsType: |
| 282 | (webrtc::PeerConnectionInterface::IceTransportsType)nativeType { |
| 283 | switch (nativeType) { |
| 284 | case webrtc::PeerConnectionInterface::kNone: |
| 285 | return RTCIceTransportPolicyNone; |
| 286 | case webrtc::PeerConnectionInterface::kRelay: |
| 287 | return RTCIceTransportPolicyRelay; |
| 288 | case webrtc::PeerConnectionInterface::kNoHost: |
| 289 | return RTCIceTransportPolicyNoHost; |
| 290 | case webrtc::PeerConnectionInterface::kAll: |
| 291 | return RTCIceTransportPolicyAll; |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | + (NSString *)stringForTransportPolicy:(RTCIceTransportPolicy)policy { |
| 296 | switch (policy) { |
| 297 | case RTCIceTransportPolicyNone: |
| 298 | return @"NONE"; |
| 299 | case RTCIceTransportPolicyRelay: |
| 300 | return @"RELAY"; |
| 301 | case RTCIceTransportPolicyNoHost: |
| 302 | return @"NO_HOST"; |
| 303 | case RTCIceTransportPolicyAll: |
| 304 | return @"ALL"; |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | + (webrtc::PeerConnectionInterface::BundlePolicy)nativeBundlePolicyForPolicy: |
| 309 | (RTCBundlePolicy)policy { |
| 310 | switch (policy) { |
| 311 | case RTCBundlePolicyBalanced: |
| 312 | return webrtc::PeerConnectionInterface::kBundlePolicyBalanced; |
| 313 | case RTCBundlePolicyMaxCompat: |
| 314 | return webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat; |
| 315 | case RTCBundlePolicyMaxBundle: |
| 316 | return webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | + (RTCBundlePolicy)bundlePolicyForNativePolicy: |
| 321 | (webrtc::PeerConnectionInterface::BundlePolicy)nativePolicy { |
| 322 | switch (nativePolicy) { |
| 323 | case webrtc::PeerConnectionInterface::kBundlePolicyBalanced: |
| 324 | return RTCBundlePolicyBalanced; |
| 325 | case webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat: |
| 326 | return RTCBundlePolicyMaxCompat; |
| 327 | case webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle: |
| 328 | return RTCBundlePolicyMaxBundle; |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | + (NSString *)stringForBundlePolicy:(RTCBundlePolicy)policy { |
| 333 | switch (policy) { |
| 334 | case RTCBundlePolicyBalanced: |
| 335 | return @"BALANCED"; |
| 336 | case RTCBundlePolicyMaxCompat: |
| 337 | return @"MAX_COMPAT"; |
| 338 | case RTCBundlePolicyMaxBundle: |
| 339 | return @"MAX_BUNDLE"; |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | + (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativeRtcpMuxPolicyForPolicy: |
| 344 | (RTCRtcpMuxPolicy)policy { |
| 345 | switch (policy) { |
| 346 | case RTCRtcpMuxPolicyNegotiate: |
| 347 | return webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate; |
| 348 | case RTCRtcpMuxPolicyRequire: |
| 349 | return webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | + (RTCRtcpMuxPolicy)rtcpMuxPolicyForNativePolicy: |
| 354 | (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativePolicy { |
| 355 | switch (nativePolicy) { |
| 356 | case webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate: |
| 357 | return RTCRtcpMuxPolicyNegotiate; |
| 358 | case webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire: |
| 359 | return RTCRtcpMuxPolicyRequire; |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | + (NSString *)stringForRtcpMuxPolicy:(RTCRtcpMuxPolicy)policy { |
| 364 | switch (policy) { |
| 365 | case RTCRtcpMuxPolicyNegotiate: |
| 366 | return @"NEGOTIATE"; |
| 367 | case RTCRtcpMuxPolicyRequire: |
| 368 | return @"REQUIRE"; |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | + (webrtc::PeerConnectionInterface::TcpCandidatePolicy) |
| 373 | nativeTcpCandidatePolicyForPolicy:(RTCTcpCandidatePolicy)policy { |
| 374 | switch (policy) { |
| 375 | case RTCTcpCandidatePolicyEnabled: |
| 376 | return webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled; |
| 377 | case RTCTcpCandidatePolicyDisabled: |
| 378 | return webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled; |
| 379 | } |
| 380 | } |
| 381 | |
Honghai Zhang | 46007ae | 2016-06-03 16:31:32 -0700 | [diff] [blame] | 382 | + (webrtc::PeerConnectionInterface::CandidateNetworkPolicy) |
| 383 | nativeCandidateNetworkPolicyForPolicy:(RTCCandidateNetworkPolicy)policy { |
| 384 | switch (policy) { |
| 385 | case RTCCandidateNetworkPolicyAll: |
| 386 | return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll; |
| 387 | case RTCCandidateNetworkPolicyLowCost: |
| 388 | return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost; |
| 389 | } |
| 390 | } |
| 391 | |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 392 | + (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativePolicy: |
| 393 | (webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativePolicy { |
| 394 | switch (nativePolicy) { |
| 395 | case webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled: |
| 396 | return RTCTcpCandidatePolicyEnabled; |
| 397 | case webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled: |
| 398 | return RTCTcpCandidatePolicyDisabled; |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | + (NSString *)stringForTcpCandidatePolicy:(RTCTcpCandidatePolicy)policy { |
| 403 | switch (policy) { |
| 404 | case RTCTcpCandidatePolicyEnabled: |
| 405 | return @"TCP_ENABLED"; |
| 406 | case RTCTcpCandidatePolicyDisabled: |
| 407 | return @"TCP_DISABLED"; |
| 408 | } |
| 409 | } |
| 410 | |
Honghai Zhang | 46007ae | 2016-06-03 16:31:32 -0700 | [diff] [blame] | 411 | + (RTCCandidateNetworkPolicy)candidateNetworkPolicyForNativePolicy: |
| 412 | (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)nativePolicy { |
| 413 | switch (nativePolicy) { |
| 414 | case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll: |
| 415 | return RTCCandidateNetworkPolicyAll; |
| 416 | case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost: |
| 417 | return RTCCandidateNetworkPolicyLowCost; |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | + (NSString *)stringForCandidateNetworkPolicy: |
| 422 | (RTCCandidateNetworkPolicy)policy { |
| 423 | switch (policy) { |
| 424 | case RTCCandidateNetworkPolicyAll: |
| 425 | return @"CANDIDATE_ALL_NETWORKS"; |
| 426 | case RTCCandidateNetworkPolicyLowCost: |
| 427 | return @"CANDIDATE_LOW_COST_NETWORKS"; |
| 428 | } |
| 429 | } |
| 430 | |
Honghai Zhang | 3108fc9 | 2016-05-11 10:10:39 -0700 | [diff] [blame] | 431 | + (webrtc::PeerConnectionInterface::ContinualGatheringPolicy) |
| 432 | nativeContinualGatheringPolicyForPolicy: |
| 433 | (RTCContinualGatheringPolicy)policy { |
| 434 | switch (policy) { |
| 435 | case RTCContinualGatheringPolicyGatherOnce: |
| 436 | return webrtc::PeerConnectionInterface::GATHER_ONCE; |
| 437 | case RTCContinualGatheringPolicyGatherContinually: |
| 438 | return webrtc::PeerConnectionInterface::GATHER_CONTINUALLY; |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | + (RTCContinualGatheringPolicy)continualGatheringPolicyForNativePolicy: |
| 443 | (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)nativePolicy { |
| 444 | switch (nativePolicy) { |
| 445 | case webrtc::PeerConnectionInterface::GATHER_ONCE: |
| 446 | return RTCContinualGatheringPolicyGatherOnce; |
| 447 | case webrtc::PeerConnectionInterface::GATHER_CONTINUALLY: |
| 448 | return RTCContinualGatheringPolicyGatherContinually; |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | + (NSString *)stringForContinualGatheringPolicy: |
| 453 | (RTCContinualGatheringPolicy)policy { |
| 454 | switch (policy) { |
| 455 | case RTCContinualGatheringPolicyGatherOnce: |
| 456 | return @"GATHER_ONCE"; |
| 457 | case RTCContinualGatheringPolicyGatherContinually: |
| 458 | return @"GATHER_CONTINUALLY"; |
| 459 | } |
| 460 | } |
| 461 | |
hbos | f9da44d | 2016-06-09 03:18:28 -0700 | [diff] [blame] | 462 | + (rtc::KeyType)nativeEncryptionKeyTypeForKeyType: |
| 463 | (RTCEncryptionKeyType)keyType { |
| 464 | switch (keyType) { |
| 465 | case RTCEncryptionKeyTypeRSA: |
| 466 | return rtc::KT_RSA; |
| 467 | case RTCEncryptionKeyTypeECDSA: |
| 468 | return rtc::KT_ECDSA; |
| 469 | } |
| 470 | } |
| 471 | |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 472 | + (webrtc::SdpSemantics)nativeSdpSemanticsForSdpSemantics:(RTCSdpSemantics)sdpSemantics { |
| 473 | switch (sdpSemantics) { |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 474 | case RTCSdpSemanticsPlanB: |
| 475 | return webrtc::SdpSemantics::kPlanB; |
| 476 | case RTCSdpSemanticsUnifiedPlan: |
| 477 | return webrtc::SdpSemantics::kUnifiedPlan; |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | + (RTCSdpSemantics)sdpSemanticsForNativeSdpSemantics:(webrtc::SdpSemantics)sdpSemantics { |
| 482 | switch (sdpSemantics) { |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 483 | case webrtc::SdpSemantics::kPlanB: |
| 484 | return RTCSdpSemanticsPlanB; |
| 485 | case webrtc::SdpSemantics::kUnifiedPlan: |
| 486 | return RTCSdpSemanticsUnifiedPlan; |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | + (NSString *)stringForSdpSemantics:(RTCSdpSemantics)sdpSemantics { |
| 491 | switch (sdpSemantics) { |
Steve Anton | 8cb344a | 2018-02-27 15:34:53 -0800 | [diff] [blame] | 492 | case RTCSdpSemanticsPlanB: |
| 493 | return @"PLAN_B"; |
| 494 | case RTCSdpSemanticsUnifiedPlan: |
| 495 | return @"UNIFIED_PLAN"; |
| 496 | } |
| 497 | } |
| 498 | |
hjon | 6d49a8e | 2016-01-26 13:06:42 -0800 | [diff] [blame] | 499 | @end |