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