blob: 0f0239f93dc7bc8c6a84eb77f8217c7aa22fcbff [file] [log] [blame]
hjon6d49a8e2016-01-26 13:06:42 -08001/*
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
tkchin9eeb6242016-04-27 01:54:20 -070011#import "RTCConfiguration+Private.h"
hjon6d49a8e2016-01-26 13:06:42 -080012
jbauch555604a2016-04-26 03:13:22 -070013#include <memory>
14
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020015#import "RTCCertificate.h"
Zeke Chinef1140e2017-10-27 15:42:08 -070016#import "RTCConfiguration+Native.h"
tkchin9eeb6242016-04-27 01:54:20 -070017#import "RTCIceServer+Private.h"
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020018#import "base/RTCLogging.h"
tkchinab8f82f2016-01-27 17:50:11 -080019
Steve Anton10542f22019-01-11 09:11:00 -080020#include "rtc_base/rtc_certificate_generator.h"
21#include "rtc_base/ssl_identity.h"
hjon6d49a8e2016-01-26 13:06:42 -080022
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020023@implementation RTC_OBJC_TYPE (RTCConfiguration)
hjon6d49a8e2016-01-26 13:06:42 -080024
Taylor Brandstetter21c80322020-03-24 15:41:19 -070025@synthesize enableDscp = _enableDscp;
hjon6d49a8e2016-01-26 13:06:42 -080026@synthesize iceServers = _iceServers;
Michael Iedemaccee56b2018-07-05 15:28:24 +020027@synthesize certificate = _certificate;
hjon6d49a8e2016-01-26 13:06:42 -080028@synthesize iceTransportPolicy = _iceTransportPolicy;
29@synthesize bundlePolicy = _bundlePolicy;
30@synthesize rtcpMuxPolicy = _rtcpMuxPolicy;
31@synthesize tcpCandidatePolicy = _tcpCandidatePolicy;
Honghai Zhang46007ae2016-06-03 16:31:32 -070032@synthesize candidateNetworkPolicy = _candidateNetworkPolicy;
Honghai Zhang3108fc92016-05-11 10:10:39 -070033@synthesize continualGatheringPolicy = _continualGatheringPolicy;
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +030034@synthesize disableIPV6 = _disableIPV6;
35@synthesize disableIPV6OnWiFi = _disableIPV6OnWiFi;
deadbeef2059bb32017-07-26 18:25:43 -070036@synthesize maxIPv6Networks = _maxIPv6Networks;
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +010037@synthesize disableLinkLocalNetworks = _disableLinkLocalNetworks;
hjon6d49a8e2016-01-26 13:06:42 -080038@synthesize audioJitterBufferMaxPackets = _audioJitterBufferMaxPackets;
hayscc9f95002016-12-05 14:24:32 -080039@synthesize audioJitterBufferFastAccelerate = _audioJitterBufferFastAccelerate;
hjon6d49a8e2016-01-26 13:06:42 -080040@synthesize iceConnectionReceivingTimeout = _iceConnectionReceivingTimeout;
41@synthesize iceBackupCandidatePairPingInterval =
42 _iceBackupCandidatePairPingInterval;
tkchinab8f82f2016-01-27 17:50:11 -080043@synthesize keyType = _keyType;
deadbeefbe0c96f2016-05-18 16:20:14 -070044@synthesize iceCandidatePoolSize = _iceCandidatePoolSize;
honghaizaf6b6e02016-07-11 15:09:26 -070045@synthesize shouldPruneTurnPorts = _shouldPruneTurnPorts;
46@synthesize shouldPresumeWritableWhenFullyRelayed =
47 _shouldPresumeWritableWhenFullyRelayed;
Qingsi Wang1fe119f2019-05-31 16:55:33 -070048@synthesize shouldSurfaceIceCandidatesOnIceTransportTypeChanged =
49 _shouldSurfaceIceCandidatesOnIceTransportTypeChanged;
skvlada5d94ff2017-02-02 13:02:30 -080050@synthesize iceCheckMinInterval = _iceCheckMinInterval;
Steve Anton8cb344a2018-02-27 15:34:53 -080051@synthesize sdpSemantics = _sdpSemantics;
Zeke Chinef1140e2017-10-27 15:42:08 -070052@synthesize turnCustomizer = _turnCustomizer;
Zhi Huangb57e1692018-06-12 11:41:11 -070053@synthesize activeResetSrtpParams = _activeResetSrtpParams;
philipel3eb84f02019-11-11 12:57:44 +010054@synthesize allowCodecSwitching = _allowCodecSwitching;
Benjamin Wright8c27cca2018-10-25 10:16:44 -070055@synthesize cryptoOptions = _cryptoOptions;
Brad Pughf24143d2020-11-16 16:27:20 -080056@synthesize turnLoggingId = _turnLoggingId;
Jiawei Oub1e47752018-11-13 23:48:19 -080057@synthesize rtcpAudioReportIntervalMs = _rtcpAudioReportIntervalMs;
58@synthesize rtcpVideoReportIntervalMs = _rtcpVideoReportIntervalMs;
Yura Yaroshevich41736142021-03-16 18:04:36 +030059@synthesize enableImplicitRollback = _enableImplicitRollback;
Yura Yaroshevichcbadb8b2021-03-17 17:39:52 +030060@synthesize offerExtmapAllowMixed = _offerExtmapAllowMixed;
Yura Yaroshevichb9fa3192021-03-31 16:48:39 +030061@synthesize iceCheckIntervalStrongConnectivity = _iceCheckIntervalStrongConnectivity;
62@synthesize iceCheckIntervalWeakConnectivity = _iceCheckIntervalWeakConnectivity;
63@synthesize iceUnwritableTimeout = _iceUnwritableTimeout;
64@synthesize iceUnwritableMinChecks = _iceUnwritableMinChecks;
65@synthesize iceInactiveTimeout = _iceInactiveTimeout;
hjon6d49a8e2016-01-26 13:06:42 -080066
67- (instancetype)init {
jtteh4eeb5372017-04-03 15:06:37 -070068 // Copy defaults.
Yuriy Pavlyshak8cec4fb2018-09-07 16:43:31 +020069 webrtc::PeerConnectionInterface::RTCConfiguration config;
jtteh465faf02017-04-04 14:00:16 -070070 return [self initWithNativeConfiguration:config];
jtteh4eeb5372017-04-03 15:06:37 -070071}
72
73- (instancetype)initWithNativeConfiguration:
jtteh465faf02017-04-04 14:00:16 -070074 (const webrtc::PeerConnectionInterface::RTCConfiguration &)config {
hjon6d49a8e2016-01-26 13:06:42 -080075 if (self = [super init]) {
Taylor Brandstetter21c80322020-03-24 15:41:19 -070076 _enableDscp = config.dscp();
jtteh4eeb5372017-04-03 15:06:37 -070077 NSMutableArray *iceServers = [NSMutableArray array];
jtteh465faf02017-04-04 14:00:16 -070078 for (const webrtc::PeerConnectionInterface::IceServer& server : config.servers) {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020079 RTC_OBJC_TYPE(RTCIceServer) *iceServer =
80 [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithNativeServer:server];
jtteh4eeb5372017-04-03 15:06:37 -070081 [iceServers addObject:iceServer];
82 }
83 _iceServers = iceServers;
Michael Iedemaccee56b2018-07-05 15:28:24 +020084 if (!config.certificates.empty()) {
85 rtc::scoped_refptr<rtc::RTCCertificate> native_cert;
86 native_cert = config.certificates[0];
87 rtc::RTCCertificatePEM native_pem = native_cert->ToPEM();
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020088 _certificate = [[RTC_OBJC_TYPE(RTCCertificate) alloc]
89 initWithPrivateKey:@(native_pem.private_key().c_str())
90 certificate:@(native_pem.certificate().c_str())];
Michael Iedemaccee56b2018-07-05 15:28:24 +020091 }
hjon6d49a8e2016-01-26 13:06:42 -080092 _iceTransportPolicy =
jtteh465faf02017-04-04 14:00:16 -070093 [[self class] transportPolicyForTransportsType:config.type];
hjon6d49a8e2016-01-26 13:06:42 -080094 _bundlePolicy =
jtteh465faf02017-04-04 14:00:16 -070095 [[self class] bundlePolicyForNativePolicy:config.bundle_policy];
hjon6d49a8e2016-01-26 13:06:42 -080096 _rtcpMuxPolicy =
jtteh465faf02017-04-04 14:00:16 -070097 [[self class] rtcpMuxPolicyForNativePolicy:config.rtcp_mux_policy];
hjon6d49a8e2016-01-26 13:06:42 -080098 _tcpCandidatePolicy = [[self class] tcpCandidatePolicyForNativePolicy:
jtteh465faf02017-04-04 14:00:16 -070099 config.tcp_candidate_policy];
Honghai Zhang46007ae2016-06-03 16:31:32 -0700100 _candidateNetworkPolicy = [[self class]
jtteh465faf02017-04-04 14:00:16 -0700101 candidateNetworkPolicyForNativePolicy:config.candidate_network_policy];
Honghai Zhang3108fc92016-05-11 10:10:39 -0700102 webrtc::PeerConnectionInterface::ContinualGatheringPolicy nativePolicy =
jtteh465faf02017-04-04 14:00:16 -0700103 config.continual_gathering_policy;
Honghai Zhang3108fc92016-05-11 10:10:39 -0700104 _continualGatheringPolicy =
105 [[self class] continualGatheringPolicyForNativePolicy:nativePolicy];
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300106 _disableIPV6 = config.disable_ipv6;
107 _disableIPV6OnWiFi = config.disable_ipv6_on_wifi;
deadbeef2059bb32017-07-26 18:25:43 -0700108 _maxIPv6Networks = config.max_ipv6_networks;
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100109 _disableLinkLocalNetworks = config.disable_link_local_networks;
jtteh465faf02017-04-04 14:00:16 -0700110 _audioJitterBufferMaxPackets = config.audio_jitter_buffer_max_packets;
111 _audioJitterBufferFastAccelerate = config.audio_jitter_buffer_fast_accelerate;
112 _iceConnectionReceivingTimeout = config.ice_connection_receiving_timeout;
hjon6d49a8e2016-01-26 13:06:42 -0800113 _iceBackupCandidatePairPingInterval =
jtteh465faf02017-04-04 14:00:16 -0700114 config.ice_backup_candidate_pair_ping_interval;
tkchinab8f82f2016-01-27 17:50:11 -0800115 _keyType = RTCEncryptionKeyTypeECDSA;
jtteh465faf02017-04-04 14:00:16 -0700116 _iceCandidatePoolSize = config.ice_candidate_pool_size;
117 _shouldPruneTurnPorts = config.prune_turn_ports;
honghaizaf6b6e02016-07-11 15:09:26 -0700118 _shouldPresumeWritableWhenFullyRelayed =
jtteh465faf02017-04-04 14:00:16 -0700119 config.presume_writable_when_fully_relayed;
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700120 _shouldSurfaceIceCandidatesOnIceTransportTypeChanged =
121 config.surface_ice_candidates_on_ice_transport_type_changed;
jtteh465faf02017-04-04 14:00:16 -0700122 if (config.ice_check_min_interval) {
skvlada5d94ff2017-02-02 13:02:30 -0800123 _iceCheckMinInterval =
jtteh465faf02017-04-04 14:00:16 -0700124 [NSNumber numberWithInt:*config.ice_check_min_interval];
skvlada5d94ff2017-02-02 13:02:30 -0800125 }
Steve Anton8cb344a2018-02-27 15:34:53 -0800126 _sdpSemantics = [[self class] sdpSemanticsForNativeSdpSemantics:config.sdp_semantics];
Zeke Chinef1140e2017-10-27 15:42:08 -0700127 _turnCustomizer = config.turn_customizer;
Zhi Huangb57e1692018-06-12 11:41:11 -0700128 _activeResetSrtpParams = config.active_reset_srtp_params;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700129 if (config.crypto_options) {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +0200130 _cryptoOptions = [[RTC_OBJC_TYPE(RTCCryptoOptions) alloc]
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700131 initWithSrtpEnableGcmCryptoSuites:config.crypto_options->srtp
132 .enable_gcm_crypto_suites
133 srtpEnableAes128Sha1_32CryptoCipher:config.crypto_options->srtp
134 .enable_aes128_sha1_32_crypto_cipher
135 srtpEnableEncryptedRtpHeaderExtensions:config.crypto_options->srtp
136 .enable_encrypted_rtp_header_extensions
137 sframeRequireFrameEncryption:config.crypto_options->sframe
138 .require_frame_encryption];
139 }
Brad Pughf24143d2020-11-16 16:27:20 -0800140 _turnLoggingId = [NSString stringWithUTF8String:config.turn_logging_id.c_str()];
Jiawei Oub1e47752018-11-13 23:48:19 -0800141 _rtcpAudioReportIntervalMs = config.audio_rtcp_report_interval_ms();
142 _rtcpVideoReportIntervalMs = config.video_rtcp_report_interval_ms();
philipel3eb84f02019-11-11 12:57:44 +0100143 _allowCodecSwitching = config.allow_codec_switching.value_or(false);
Yura Yaroshevich41736142021-03-16 18:04:36 +0300144 _enableImplicitRollback = config.enable_implicit_rollback;
Yura Yaroshevichcbadb8b2021-03-17 17:39:52 +0300145 _offerExtmapAllowMixed = config.offer_extmap_allow_mixed;
Yura Yaroshevichb9fa3192021-03-31 16:48:39 +0300146 _iceCheckIntervalStrongConnectivity =
147 config.ice_check_interval_strong_connectivity.has_value() ?
148 [NSNumber numberWithInt:*config.ice_check_interval_strong_connectivity] :
149 nil;
150 _iceCheckIntervalWeakConnectivity = config.ice_check_interval_weak_connectivity.has_value() ?
151 [NSNumber numberWithInt:*config.ice_check_interval_weak_connectivity] :
152 nil;
153 _iceUnwritableTimeout = config.ice_unwritable_timeout.has_value() ?
154 [NSNumber numberWithInt:*config.ice_unwritable_timeout] :
155 nil;
156 _iceUnwritableMinChecks = config.ice_unwritable_min_checks.has_value() ?
157 [NSNumber numberWithInt:*config.ice_unwritable_min_checks] :
158 nil;
159 _iceInactiveTimeout = config.ice_inactive_timeout.has_value() ?
160 [NSNumber numberWithInt:*config.ice_inactive_timeout] :
161 nil;
hjon6d49a8e2016-01-26 13:06:42 -0800162 }
163 return self;
164}
165
166- (NSString *)description {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +0200167 static NSString *formatString = @"RTC_OBJC_TYPE(RTCConfiguration): "
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300168 @"{\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%d\n%d\n%d\n%d\n%d\n%d\n"
Yura Yaroshevich11539742021-04-20 13:38:36 +0300169 @"%d\n%@\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n}\n";
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100170
Steve Anton8cb344a2018-02-27 15:34:53 -0800171 return [NSString
172 stringWithFormat:formatString,
173 _iceServers,
174 [[self class] stringForTransportPolicy:_iceTransportPolicy],
175 [[self class] stringForBundlePolicy:_bundlePolicy],
176 [[self class] stringForRtcpMuxPolicy:_rtcpMuxPolicy],
177 [[self class] stringForTcpCandidatePolicy:_tcpCandidatePolicy],
178 [[self class] stringForCandidateNetworkPolicy:_candidateNetworkPolicy],
179 [[self class] stringForContinualGatheringPolicy:_continualGatheringPolicy],
180 [[self class] stringForSdpSemantics:_sdpSemantics],
181 _audioJitterBufferMaxPackets,
182 _audioJitterBufferFastAccelerate,
183 _iceConnectionReceivingTimeout,
184 _iceBackupCandidatePairPingInterval,
185 _iceCandidatePoolSize,
186 _shouldPruneTurnPorts,
187 _shouldPresumeWritableWhenFullyRelayed,
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700188 _shouldSurfaceIceCandidatesOnIceTransportTypeChanged,
Steve Anton8cb344a2018-02-27 15:34:53 -0800189 _iceCheckMinInterval,
Steve Anton8cb344a2018-02-27 15:34:53 -0800190 _disableLinkLocalNetworks,
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300191 _disableIPV6,
192 _disableIPV6OnWiFi,
Zhi Huangb57e1692018-06-12 11:41:11 -0700193 _maxIPv6Networks,
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -0700194 _activeResetSrtpParams,
Yura Yaroshevich41736142021-03-16 18:04:36 +0300195 _enableDscp,
196 _enableImplicitRollback];
hjon6d49a8e2016-01-26 13:06:42 -0800197}
198
199#pragma mark - Private
200
hbosa73ca562016-05-17 03:28:58 -0700201- (webrtc::PeerConnectionInterface::RTCConfiguration *)
202 createNativeConfiguration {
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200203 std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration>
Honghai Zhangf7ddc062016-09-01 15:34:01 -0700204 nativeConfig(new webrtc::PeerConnectionInterface::RTCConfiguration(
205 webrtc::PeerConnectionInterface::RTCConfigurationType::kAggressive));
hjon6d49a8e2016-01-26 13:06:42 -0800206
Taylor Brandstetter21c80322020-03-24 15:41:19 -0700207 nativeConfig->set_dscp(_enableDscp);
Mirko Bonadeia81e9c82020-05-04 16:14:32 +0200208 for (RTC_OBJC_TYPE(RTCIceServer) * iceServer in _iceServers) {
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200209 nativeConfig->servers.push_back(iceServer.nativeServer);
hjon6d49a8e2016-01-26 13:06:42 -0800210 }
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200211 nativeConfig->type =
hjon6d49a8e2016-01-26 13:06:42 -0800212 [[self class] nativeTransportsTypeForTransportPolicy:_iceTransportPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200213 nativeConfig->bundle_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800214 [[self class] nativeBundlePolicyForPolicy:_bundlePolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200215 nativeConfig->rtcp_mux_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800216 [[self class] nativeRtcpMuxPolicyForPolicy:_rtcpMuxPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200217 nativeConfig->tcp_candidate_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800218 [[self class] nativeTcpCandidatePolicyForPolicy:_tcpCandidatePolicy];
Honghai Zhang46007ae2016-06-03 16:31:32 -0700219 nativeConfig->candidate_network_policy = [[self class]
220 nativeCandidateNetworkPolicyForPolicy:_candidateNetworkPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200221 nativeConfig->continual_gathering_policy = [[self class]
Honghai Zhang3108fc92016-05-11 10:10:39 -0700222 nativeContinualGatheringPolicyForPolicy:_continualGatheringPolicy];
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300223 nativeConfig->disable_ipv6 = _disableIPV6;
224 nativeConfig->disable_ipv6_on_wifi = _disableIPV6OnWiFi;
deadbeef2059bb32017-07-26 18:25:43 -0700225 nativeConfig->max_ipv6_networks = _maxIPv6Networks;
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100226 nativeConfig->disable_link_local_networks = _disableLinkLocalNetworks;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200227 nativeConfig->audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets;
hayscc9f95002016-12-05 14:24:32 -0800228 nativeConfig->audio_jitter_buffer_fast_accelerate =
229 _audioJitterBufferFastAccelerate ? true : false;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200230 nativeConfig->ice_connection_receiving_timeout =
hjon6d49a8e2016-01-26 13:06:42 -0800231 _iceConnectionReceivingTimeout;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200232 nativeConfig->ice_backup_candidate_pair_ping_interval =
hjon6d49a8e2016-01-26 13:06:42 -0800233 _iceBackupCandidatePairPingInterval;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200234 rtc::KeyType keyType =
235 [[self class] nativeEncryptionKeyTypeForKeyType:_keyType];
Michael Iedemaccee56b2018-07-05 15:28:24 +0200236 if (_certificate != nullptr) {
237 // if offered a pemcert use it...
238 RTC_LOG(LS_INFO) << "Have configured cert - using it.";
239 std::string pem_private_key = [[_certificate private_key] UTF8String];
240 std::string pem_certificate = [[_certificate certificate] UTF8String];
241 rtc::RTCCertificatePEM pem = rtc::RTCCertificatePEM(pem_private_key, pem_certificate);
242 rtc::scoped_refptr<rtc::RTCCertificate> certificate = rtc::RTCCertificate::FromPEM(pem);
243 RTC_LOG(LS_INFO) << "Created cert from PEM strings.";
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200244 if (!certificate) {
Michael Iedemaccee56b2018-07-05 15:28:24 +0200245 RTC_LOG(LS_ERROR) << "Failed to generate certificate from PEM.";
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200246 return nullptr;
tkchinab8f82f2016-01-27 17:50:11 -0800247 }
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200248 nativeConfig->certificates.push_back(certificate);
Michael Iedemaccee56b2018-07-05 15:28:24 +0200249 } else {
250 RTC_LOG(LS_INFO) << "Don't have configured cert.";
251 // Generate non-default certificate.
252 if (keyType != rtc::KT_DEFAULT) {
253 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
254 rtc::RTCCertificateGenerator::GenerateCertificate(rtc::KeyParams(keyType),
255 absl::optional<uint64_t>());
256 if (!certificate) {
257 RTCLogError(@"Failed to generate certificate.");
258 return nullptr;
259 }
260 nativeConfig->certificates.push_back(certificate);
261 }
tkchinab8f82f2016-01-27 17:50:11 -0800262 }
deadbeefbe0c96f2016-05-18 16:20:14 -0700263 nativeConfig->ice_candidate_pool_size = _iceCandidatePoolSize;
honghaizaf6b6e02016-07-11 15:09:26 -0700264 nativeConfig->prune_turn_ports = _shouldPruneTurnPorts ? true : false;
Taylor Brandstettere9851112016-07-01 11:11:13 -0700265 nativeConfig->presume_writable_when_fully_relayed =
honghaizaf6b6e02016-07-11 15:09:26 -0700266 _shouldPresumeWritableWhenFullyRelayed ? true : false;
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700267 nativeConfig->surface_ice_candidates_on_ice_transport_type_changed =
268 _shouldSurfaceIceCandidatesOnIceTransportTypeChanged ? true : false;
skvlada5d94ff2017-02-02 13:02:30 -0800269 if (_iceCheckMinInterval != nil) {
Danil Chapovalov196100e2018-06-21 10:17:24 +0200270 nativeConfig->ice_check_min_interval = absl::optional<int>(_iceCheckMinInterval.intValue);
skvlada5d94ff2017-02-02 13:02:30 -0800271 }
Steve Anton8cb344a2018-02-27 15:34:53 -0800272 nativeConfig->sdp_semantics = [[self class] nativeSdpSemanticsForSdpSemantics:_sdpSemantics];
Zeke Chinef1140e2017-10-27 15:42:08 -0700273 if (_turnCustomizer) {
274 nativeConfig->turn_customizer = _turnCustomizer;
275 }
Zhi Huangb57e1692018-06-12 11:41:11 -0700276 nativeConfig->active_reset_srtp_params = _activeResetSrtpParams ? true : false;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700277 if (_cryptoOptions) {
278 webrtc::CryptoOptions nativeCryptoOptions;
279 nativeCryptoOptions.srtp.enable_gcm_crypto_suites =
280 _cryptoOptions.srtpEnableGcmCryptoSuites ? true : false;
281 nativeCryptoOptions.srtp.enable_aes128_sha1_32_crypto_cipher =
282 _cryptoOptions.srtpEnableAes128Sha1_32CryptoCipher ? true : false;
283 nativeCryptoOptions.srtp.enable_encrypted_rtp_header_extensions =
284 _cryptoOptions.srtpEnableEncryptedRtpHeaderExtensions ? true : false;
285 nativeCryptoOptions.sframe.require_frame_encryption =
286 _cryptoOptions.sframeRequireFrameEncryption ? true : false;
287 nativeConfig->crypto_options = absl::optional<webrtc::CryptoOptions>(nativeCryptoOptions);
288 }
Brad Pughf24143d2020-11-16 16:27:20 -0800289 nativeConfig->turn_logging_id = [_turnLoggingId UTF8String];
Jiawei Oub1e47752018-11-13 23:48:19 -0800290 nativeConfig->set_audio_rtcp_report_interval_ms(_rtcpAudioReportIntervalMs);
291 nativeConfig->set_video_rtcp_report_interval_ms(_rtcpVideoReportIntervalMs);
philipel3eb84f02019-11-11 12:57:44 +0100292 nativeConfig->allow_codec_switching = _allowCodecSwitching;
Yura Yaroshevich41736142021-03-16 18:04:36 +0300293 nativeConfig->enable_implicit_rollback = _enableImplicitRollback;
Yura Yaroshevichcbadb8b2021-03-17 17:39:52 +0300294 nativeConfig->offer_extmap_allow_mixed = _offerExtmapAllowMixed;
Yura Yaroshevichb9fa3192021-03-31 16:48:39 +0300295 if (_iceCheckIntervalStrongConnectivity != nil) {
296 nativeConfig->ice_check_interval_strong_connectivity =
297 absl::optional<int>(_iceCheckIntervalStrongConnectivity.intValue);
298 }
299 if (_iceCheckIntervalWeakConnectivity != nil) {
300 nativeConfig->ice_check_interval_weak_connectivity =
301 absl::optional<int>(_iceCheckIntervalWeakConnectivity.intValue);
302 }
303 if (_iceUnwritableTimeout != nil) {
304 nativeConfig->ice_unwritable_timeout = absl::optional<int>(_iceUnwritableTimeout.intValue);
305 }
306 if (_iceUnwritableMinChecks != nil) {
307 nativeConfig->ice_unwritable_min_checks = absl::optional<int>(_iceUnwritableMinChecks.intValue);
308 }
309 if (_iceInactiveTimeout != nil) {
310 nativeConfig->ice_inactive_timeout = absl::optional<int>(_iceInactiveTimeout.intValue);
311 }
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200312 return nativeConfig.release();
hjon6d49a8e2016-01-26 13:06:42 -0800313}
314
hjon6d49a8e2016-01-26 13:06:42 -0800315+ (webrtc::PeerConnectionInterface::IceTransportsType)
316 nativeTransportsTypeForTransportPolicy:(RTCIceTransportPolicy)policy {
317 switch (policy) {
318 case RTCIceTransportPolicyNone:
319 return webrtc::PeerConnectionInterface::kNone;
320 case RTCIceTransportPolicyRelay:
321 return webrtc::PeerConnectionInterface::kRelay;
322 case RTCIceTransportPolicyNoHost:
323 return webrtc::PeerConnectionInterface::kNoHost;
324 case RTCIceTransportPolicyAll:
325 return webrtc::PeerConnectionInterface::kAll;
326 }
327}
328
329+ (RTCIceTransportPolicy)transportPolicyForTransportsType:
330 (webrtc::PeerConnectionInterface::IceTransportsType)nativeType {
331 switch (nativeType) {
332 case webrtc::PeerConnectionInterface::kNone:
333 return RTCIceTransportPolicyNone;
334 case webrtc::PeerConnectionInterface::kRelay:
335 return RTCIceTransportPolicyRelay;
336 case webrtc::PeerConnectionInterface::kNoHost:
337 return RTCIceTransportPolicyNoHost;
338 case webrtc::PeerConnectionInterface::kAll:
339 return RTCIceTransportPolicyAll;
340 }
341}
342
343+ (NSString *)stringForTransportPolicy:(RTCIceTransportPolicy)policy {
344 switch (policy) {
345 case RTCIceTransportPolicyNone:
346 return @"NONE";
347 case RTCIceTransportPolicyRelay:
348 return @"RELAY";
349 case RTCIceTransportPolicyNoHost:
350 return @"NO_HOST";
351 case RTCIceTransportPolicyAll:
352 return @"ALL";
353 }
354}
355
356+ (webrtc::PeerConnectionInterface::BundlePolicy)nativeBundlePolicyForPolicy:
357 (RTCBundlePolicy)policy {
358 switch (policy) {
359 case RTCBundlePolicyBalanced:
360 return webrtc::PeerConnectionInterface::kBundlePolicyBalanced;
361 case RTCBundlePolicyMaxCompat:
362 return webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat;
363 case RTCBundlePolicyMaxBundle:
364 return webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle;
365 }
366}
367
368+ (RTCBundlePolicy)bundlePolicyForNativePolicy:
369 (webrtc::PeerConnectionInterface::BundlePolicy)nativePolicy {
370 switch (nativePolicy) {
371 case webrtc::PeerConnectionInterface::kBundlePolicyBalanced:
372 return RTCBundlePolicyBalanced;
373 case webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat:
374 return RTCBundlePolicyMaxCompat;
375 case webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle:
376 return RTCBundlePolicyMaxBundle;
377 }
378}
379
380+ (NSString *)stringForBundlePolicy:(RTCBundlePolicy)policy {
381 switch (policy) {
382 case RTCBundlePolicyBalanced:
383 return @"BALANCED";
384 case RTCBundlePolicyMaxCompat:
385 return @"MAX_COMPAT";
386 case RTCBundlePolicyMaxBundle:
387 return @"MAX_BUNDLE";
388 }
389}
390
391+ (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativeRtcpMuxPolicyForPolicy:
392 (RTCRtcpMuxPolicy)policy {
393 switch (policy) {
394 case RTCRtcpMuxPolicyNegotiate:
395 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
396 case RTCRtcpMuxPolicyRequire:
397 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire;
398 }
399}
400
401+ (RTCRtcpMuxPolicy)rtcpMuxPolicyForNativePolicy:
402 (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativePolicy {
403 switch (nativePolicy) {
404 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate:
405 return RTCRtcpMuxPolicyNegotiate;
406 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire:
407 return RTCRtcpMuxPolicyRequire;
408 }
409}
410
411+ (NSString *)stringForRtcpMuxPolicy:(RTCRtcpMuxPolicy)policy {
412 switch (policy) {
413 case RTCRtcpMuxPolicyNegotiate:
414 return @"NEGOTIATE";
415 case RTCRtcpMuxPolicyRequire:
416 return @"REQUIRE";
417 }
418}
419
420+ (webrtc::PeerConnectionInterface::TcpCandidatePolicy)
421 nativeTcpCandidatePolicyForPolicy:(RTCTcpCandidatePolicy)policy {
422 switch (policy) {
423 case RTCTcpCandidatePolicyEnabled:
424 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled;
425 case RTCTcpCandidatePolicyDisabled:
426 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled;
427 }
428}
429
Honghai Zhang46007ae2016-06-03 16:31:32 -0700430+ (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)
431 nativeCandidateNetworkPolicyForPolicy:(RTCCandidateNetworkPolicy)policy {
432 switch (policy) {
433 case RTCCandidateNetworkPolicyAll:
434 return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll;
435 case RTCCandidateNetworkPolicyLowCost:
436 return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
437 }
438}
439
hjon6d49a8e2016-01-26 13:06:42 -0800440+ (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativePolicy:
441 (webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativePolicy {
442 switch (nativePolicy) {
443 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled:
444 return RTCTcpCandidatePolicyEnabled;
445 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled:
446 return RTCTcpCandidatePolicyDisabled;
447 }
448}
449
450+ (NSString *)stringForTcpCandidatePolicy:(RTCTcpCandidatePolicy)policy {
451 switch (policy) {
452 case RTCTcpCandidatePolicyEnabled:
453 return @"TCP_ENABLED";
454 case RTCTcpCandidatePolicyDisabled:
455 return @"TCP_DISABLED";
456 }
457}
458
Honghai Zhang46007ae2016-06-03 16:31:32 -0700459+ (RTCCandidateNetworkPolicy)candidateNetworkPolicyForNativePolicy:
460 (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)nativePolicy {
461 switch (nativePolicy) {
462 case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll:
463 return RTCCandidateNetworkPolicyAll;
464 case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost:
465 return RTCCandidateNetworkPolicyLowCost;
466 }
467}
468
469+ (NSString *)stringForCandidateNetworkPolicy:
470 (RTCCandidateNetworkPolicy)policy {
471 switch (policy) {
472 case RTCCandidateNetworkPolicyAll:
473 return @"CANDIDATE_ALL_NETWORKS";
474 case RTCCandidateNetworkPolicyLowCost:
475 return @"CANDIDATE_LOW_COST_NETWORKS";
476 }
477}
478
Honghai Zhang3108fc92016-05-11 10:10:39 -0700479+ (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)
480 nativeContinualGatheringPolicyForPolicy:
481 (RTCContinualGatheringPolicy)policy {
482 switch (policy) {
483 case RTCContinualGatheringPolicyGatherOnce:
484 return webrtc::PeerConnectionInterface::GATHER_ONCE;
485 case RTCContinualGatheringPolicyGatherContinually:
486 return webrtc::PeerConnectionInterface::GATHER_CONTINUALLY;
487 }
488}
489
490+ (RTCContinualGatheringPolicy)continualGatheringPolicyForNativePolicy:
491 (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)nativePolicy {
492 switch (nativePolicy) {
493 case webrtc::PeerConnectionInterface::GATHER_ONCE:
494 return RTCContinualGatheringPolicyGatherOnce;
495 case webrtc::PeerConnectionInterface::GATHER_CONTINUALLY:
496 return RTCContinualGatheringPolicyGatherContinually;
497 }
498}
499
500+ (NSString *)stringForContinualGatheringPolicy:
501 (RTCContinualGatheringPolicy)policy {
502 switch (policy) {
503 case RTCContinualGatheringPolicyGatherOnce:
504 return @"GATHER_ONCE";
505 case RTCContinualGatheringPolicyGatherContinually:
506 return @"GATHER_CONTINUALLY";
507 }
508}
509
hbosf9da44d2016-06-09 03:18:28 -0700510+ (rtc::KeyType)nativeEncryptionKeyTypeForKeyType:
511 (RTCEncryptionKeyType)keyType {
512 switch (keyType) {
513 case RTCEncryptionKeyTypeRSA:
514 return rtc::KT_RSA;
515 case RTCEncryptionKeyTypeECDSA:
516 return rtc::KT_ECDSA;
517 }
518}
519
Steve Anton8cb344a2018-02-27 15:34:53 -0800520+ (webrtc::SdpSemantics)nativeSdpSemanticsForSdpSemantics:(RTCSdpSemantics)sdpSemantics {
521 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800522 case RTCSdpSemanticsPlanB:
523 return webrtc::SdpSemantics::kPlanB;
524 case RTCSdpSemanticsUnifiedPlan:
525 return webrtc::SdpSemantics::kUnifiedPlan;
526 }
527}
528
529+ (RTCSdpSemantics)sdpSemanticsForNativeSdpSemantics:(webrtc::SdpSemantics)sdpSemantics {
530 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800531 case webrtc::SdpSemantics::kPlanB:
532 return RTCSdpSemanticsPlanB;
533 case webrtc::SdpSemantics::kUnifiedPlan:
534 return RTCSdpSemanticsUnifiedPlan;
535 }
536}
537
538+ (NSString *)stringForSdpSemantics:(RTCSdpSemantics)sdpSemantics {
539 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800540 case RTCSdpSemanticsPlanB:
541 return @"PLAN_B";
542 case RTCSdpSemanticsUnifiedPlan:
543 return @"UNIFIED_PLAN";
544 }
545}
546
hjon6d49a8e2016-01-26 13:06:42 -0800547@end