blob: 859aa8ad76a73c4af2dd23180c3586963c1f015b [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
Henrik Boström62995db2022-01-03 09:58:10 +010020#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 09:11:00 -080021#include "rtc_base/rtc_certificate_generator.h"
22#include "rtc_base/ssl_identity.h"
hjon6d49a8e2016-01-26 13:06:42 -080023
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020024@implementation RTC_OBJC_TYPE (RTCConfiguration)
hjon6d49a8e2016-01-26 13:06:42 -080025
Taylor Brandstetter21c80322020-03-24 15:41:19 -070026@synthesize enableDscp = _enableDscp;
hjon6d49a8e2016-01-26 13:06:42 -080027@synthesize iceServers = _iceServers;
Michael Iedemaccee56b2018-07-05 15:28:24 +020028@synthesize certificate = _certificate;
hjon6d49a8e2016-01-26 13:06:42 -080029@synthesize iceTransportPolicy = _iceTransportPolicy;
30@synthesize bundlePolicy = _bundlePolicy;
31@synthesize rtcpMuxPolicy = _rtcpMuxPolicy;
32@synthesize tcpCandidatePolicy = _tcpCandidatePolicy;
Honghai Zhang46007ae2016-06-03 16:31:32 -070033@synthesize candidateNetworkPolicy = _candidateNetworkPolicy;
Honghai Zhang3108fc92016-05-11 10:10:39 -070034@synthesize continualGatheringPolicy = _continualGatheringPolicy;
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +030035@synthesize disableIPV6 = _disableIPV6;
36@synthesize disableIPV6OnWiFi = _disableIPV6OnWiFi;
deadbeef2059bb32017-07-26 18:25:43 -070037@synthesize maxIPv6Networks = _maxIPv6Networks;
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +010038@synthesize disableLinkLocalNetworks = _disableLinkLocalNetworks;
hjon6d49a8e2016-01-26 13:06:42 -080039@synthesize audioJitterBufferMaxPackets = _audioJitterBufferMaxPackets;
hayscc9f95002016-12-05 14:24:32 -080040@synthesize audioJitterBufferFastAccelerate = _audioJitterBufferFastAccelerate;
hjon6d49a8e2016-01-26 13:06:42 -080041@synthesize iceConnectionReceivingTimeout = _iceConnectionReceivingTimeout;
42@synthesize iceBackupCandidatePairPingInterval =
43 _iceBackupCandidatePairPingInterval;
tkchinab8f82f2016-01-27 17:50:11 -080044@synthesize keyType = _keyType;
deadbeefbe0c96f2016-05-18 16:20:14 -070045@synthesize iceCandidatePoolSize = _iceCandidatePoolSize;
honghaizaf6b6e02016-07-11 15:09:26 -070046@synthesize shouldPruneTurnPorts = _shouldPruneTurnPorts;
47@synthesize shouldPresumeWritableWhenFullyRelayed =
48 _shouldPresumeWritableWhenFullyRelayed;
Qingsi Wang1fe119f2019-05-31 16:55:33 -070049@synthesize shouldSurfaceIceCandidatesOnIceTransportTypeChanged =
50 _shouldSurfaceIceCandidatesOnIceTransportTypeChanged;
skvlada5d94ff2017-02-02 13:02:30 -080051@synthesize iceCheckMinInterval = _iceCheckMinInterval;
Steve Anton8cb344a2018-02-27 15:34:53 -080052@synthesize sdpSemantics = _sdpSemantics;
Zeke Chinef1140e2017-10-27 15:42:08 -070053@synthesize turnCustomizer = _turnCustomizer;
Zhi Huangb57e1692018-06-12 11:41:11 -070054@synthesize activeResetSrtpParams = _activeResetSrtpParams;
philipel3eb84f02019-11-11 12:57:44 +010055@synthesize allowCodecSwitching = _allowCodecSwitching;
Benjamin Wright8c27cca2018-10-25 10:16:44 -070056@synthesize cryptoOptions = _cryptoOptions;
Brad Pughf24143d2020-11-16 16:27:20 -080057@synthesize turnLoggingId = _turnLoggingId;
Jiawei Oub1e47752018-11-13 23:48:19 -080058@synthesize rtcpAudioReportIntervalMs = _rtcpAudioReportIntervalMs;
59@synthesize rtcpVideoReportIntervalMs = _rtcpVideoReportIntervalMs;
Yura Yaroshevich41736142021-03-16 18:04:36 +030060@synthesize enableImplicitRollback = _enableImplicitRollback;
Yura Yaroshevichcbadb8b2021-03-17 17:39:52 +030061@synthesize offerExtmapAllowMixed = _offerExtmapAllowMixed;
Yura Yaroshevichb9fa3192021-03-31 16:48:39 +030062@synthesize iceCheckIntervalStrongConnectivity = _iceCheckIntervalStrongConnectivity;
63@synthesize iceCheckIntervalWeakConnectivity = _iceCheckIntervalWeakConnectivity;
64@synthesize iceUnwritableTimeout = _iceUnwritableTimeout;
65@synthesize iceUnwritableMinChecks = _iceUnwritableMinChecks;
66@synthesize iceInactiveTimeout = _iceInactiveTimeout;
hjon6d49a8e2016-01-26 13:06:42 -080067
68- (instancetype)init {
jtteh4eeb5372017-04-03 15:06:37 -070069 // Copy defaults.
Yuriy Pavlyshak8cec4fb2018-09-07 16:43:31 +020070 webrtc::PeerConnectionInterface::RTCConfiguration config;
Henrik Boström2832bbf2022-01-21 09:49:31 +010071 config.sdp_semantics = webrtc::SdpSemantics::kUnifiedPlan;
jtteh465faf02017-04-04 14:00:16 -070072 return [self initWithNativeConfiguration:config];
jtteh4eeb5372017-04-03 15:06:37 -070073}
74
75- (instancetype)initWithNativeConfiguration:
jtteh465faf02017-04-04 14:00:16 -070076 (const webrtc::PeerConnectionInterface::RTCConfiguration &)config {
hjon6d49a8e2016-01-26 13:06:42 -080077 if (self = [super init]) {
Taylor Brandstetter21c80322020-03-24 15:41:19 -070078 _enableDscp = config.dscp();
jtteh4eeb5372017-04-03 15:06:37 -070079 NSMutableArray *iceServers = [NSMutableArray array];
jtteh465faf02017-04-04 14:00:16 -070080 for (const webrtc::PeerConnectionInterface::IceServer& server : config.servers) {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020081 RTC_OBJC_TYPE(RTCIceServer) *iceServer =
82 [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithNativeServer:server];
jtteh4eeb5372017-04-03 15:06:37 -070083 [iceServers addObject:iceServer];
84 }
85 _iceServers = iceServers;
Michael Iedemaccee56b2018-07-05 15:28:24 +020086 if (!config.certificates.empty()) {
87 rtc::scoped_refptr<rtc::RTCCertificate> native_cert;
88 native_cert = config.certificates[0];
89 rtc::RTCCertificatePEM native_pem = native_cert->ToPEM();
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020090 _certificate = [[RTC_OBJC_TYPE(RTCCertificate) alloc]
91 initWithPrivateKey:@(native_pem.private_key().c_str())
92 certificate:@(native_pem.certificate().c_str())];
Michael Iedemaccee56b2018-07-05 15:28:24 +020093 }
hjon6d49a8e2016-01-26 13:06:42 -080094 _iceTransportPolicy =
jtteh465faf02017-04-04 14:00:16 -070095 [[self class] transportPolicyForTransportsType:config.type];
hjon6d49a8e2016-01-26 13:06:42 -080096 _bundlePolicy =
jtteh465faf02017-04-04 14:00:16 -070097 [[self class] bundlePolicyForNativePolicy:config.bundle_policy];
hjon6d49a8e2016-01-26 13:06:42 -080098 _rtcpMuxPolicy =
jtteh465faf02017-04-04 14:00:16 -070099 [[self class] rtcpMuxPolicyForNativePolicy:config.rtcp_mux_policy];
hjon6d49a8e2016-01-26 13:06:42 -0800100 _tcpCandidatePolicy = [[self class] tcpCandidatePolicyForNativePolicy:
jtteh465faf02017-04-04 14:00:16 -0700101 config.tcp_candidate_policy];
Honghai Zhang46007ae2016-06-03 16:31:32 -0700102 _candidateNetworkPolicy = [[self class]
jtteh465faf02017-04-04 14:00:16 -0700103 candidateNetworkPolicyForNativePolicy:config.candidate_network_policy];
Honghai Zhang3108fc92016-05-11 10:10:39 -0700104 webrtc::PeerConnectionInterface::ContinualGatheringPolicy nativePolicy =
jtteh465faf02017-04-04 14:00:16 -0700105 config.continual_gathering_policy;
Honghai Zhang3108fc92016-05-11 10:10:39 -0700106 _continualGatheringPolicy =
107 [[self class] continualGatheringPolicyForNativePolicy:nativePolicy];
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300108 _disableIPV6 = config.disable_ipv6;
109 _disableIPV6OnWiFi = config.disable_ipv6_on_wifi;
deadbeef2059bb32017-07-26 18:25:43 -0700110 _maxIPv6Networks = config.max_ipv6_networks;
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100111 _disableLinkLocalNetworks = config.disable_link_local_networks;
jtteh465faf02017-04-04 14:00:16 -0700112 _audioJitterBufferMaxPackets = config.audio_jitter_buffer_max_packets;
113 _audioJitterBufferFastAccelerate = config.audio_jitter_buffer_fast_accelerate;
114 _iceConnectionReceivingTimeout = config.ice_connection_receiving_timeout;
hjon6d49a8e2016-01-26 13:06:42 -0800115 _iceBackupCandidatePairPingInterval =
jtteh465faf02017-04-04 14:00:16 -0700116 config.ice_backup_candidate_pair_ping_interval;
tkchinab8f82f2016-01-27 17:50:11 -0800117 _keyType = RTCEncryptionKeyTypeECDSA;
jtteh465faf02017-04-04 14:00:16 -0700118 _iceCandidatePoolSize = config.ice_candidate_pool_size;
119 _shouldPruneTurnPorts = config.prune_turn_ports;
honghaizaf6b6e02016-07-11 15:09:26 -0700120 _shouldPresumeWritableWhenFullyRelayed =
jtteh465faf02017-04-04 14:00:16 -0700121 config.presume_writable_when_fully_relayed;
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700122 _shouldSurfaceIceCandidatesOnIceTransportTypeChanged =
123 config.surface_ice_candidates_on_ice_transport_type_changed;
jtteh465faf02017-04-04 14:00:16 -0700124 if (config.ice_check_min_interval) {
skvlada5d94ff2017-02-02 13:02:30 -0800125 _iceCheckMinInterval =
jtteh465faf02017-04-04 14:00:16 -0700126 [NSNumber numberWithInt:*config.ice_check_min_interval];
skvlada5d94ff2017-02-02 13:02:30 -0800127 }
Steve Anton8cb344a2018-02-27 15:34:53 -0800128 _sdpSemantics = [[self class] sdpSemanticsForNativeSdpSemantics:config.sdp_semantics];
Zeke Chinef1140e2017-10-27 15:42:08 -0700129 _turnCustomizer = config.turn_customizer;
Zhi Huangb57e1692018-06-12 11:41:11 -0700130 _activeResetSrtpParams = config.active_reset_srtp_params;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700131 if (config.crypto_options) {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +0200132 _cryptoOptions = [[RTC_OBJC_TYPE(RTCCryptoOptions) alloc]
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700133 initWithSrtpEnableGcmCryptoSuites:config.crypto_options->srtp
134 .enable_gcm_crypto_suites
135 srtpEnableAes128Sha1_32CryptoCipher:config.crypto_options->srtp
136 .enable_aes128_sha1_32_crypto_cipher
137 srtpEnableEncryptedRtpHeaderExtensions:config.crypto_options->srtp
138 .enable_encrypted_rtp_header_extensions
139 sframeRequireFrameEncryption:config.crypto_options->sframe
140 .require_frame_encryption];
141 }
Brad Pughf24143d2020-11-16 16:27:20 -0800142 _turnLoggingId = [NSString stringWithUTF8String:config.turn_logging_id.c_str()];
Jiawei Oub1e47752018-11-13 23:48:19 -0800143 _rtcpAudioReportIntervalMs = config.audio_rtcp_report_interval_ms();
144 _rtcpVideoReportIntervalMs = config.video_rtcp_report_interval_ms();
philipel3eb84f02019-11-11 12:57:44 +0100145 _allowCodecSwitching = config.allow_codec_switching.value_or(false);
Yura Yaroshevich41736142021-03-16 18:04:36 +0300146 _enableImplicitRollback = config.enable_implicit_rollback;
Yura Yaroshevichcbadb8b2021-03-17 17:39:52 +0300147 _offerExtmapAllowMixed = config.offer_extmap_allow_mixed;
Yura Yaroshevichb9fa3192021-03-31 16:48:39 +0300148 _iceCheckIntervalStrongConnectivity =
149 config.ice_check_interval_strong_connectivity.has_value() ?
150 [NSNumber numberWithInt:*config.ice_check_interval_strong_connectivity] :
151 nil;
152 _iceCheckIntervalWeakConnectivity = config.ice_check_interval_weak_connectivity.has_value() ?
153 [NSNumber numberWithInt:*config.ice_check_interval_weak_connectivity] :
154 nil;
155 _iceUnwritableTimeout = config.ice_unwritable_timeout.has_value() ?
156 [NSNumber numberWithInt:*config.ice_unwritable_timeout] :
157 nil;
158 _iceUnwritableMinChecks = config.ice_unwritable_min_checks.has_value() ?
159 [NSNumber numberWithInt:*config.ice_unwritable_min_checks] :
160 nil;
161 _iceInactiveTimeout = config.ice_inactive_timeout.has_value() ?
162 [NSNumber numberWithInt:*config.ice_inactive_timeout] :
163 nil;
hjon6d49a8e2016-01-26 13:06:42 -0800164 }
165 return self;
166}
167
168- (NSString *)description {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +0200169 static NSString *formatString = @"RTC_OBJC_TYPE(RTCConfiguration): "
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300170 @"{\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 +0300171 @"%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 +0100172
Steve Anton8cb344a2018-02-27 15:34:53 -0800173 return [NSString
174 stringWithFormat:formatString,
175 _iceServers,
176 [[self class] stringForTransportPolicy:_iceTransportPolicy],
177 [[self class] stringForBundlePolicy:_bundlePolicy],
178 [[self class] stringForRtcpMuxPolicy:_rtcpMuxPolicy],
179 [[self class] stringForTcpCandidatePolicy:_tcpCandidatePolicy],
180 [[self class] stringForCandidateNetworkPolicy:_candidateNetworkPolicy],
181 [[self class] stringForContinualGatheringPolicy:_continualGatheringPolicy],
182 [[self class] stringForSdpSemantics:_sdpSemantics],
183 _audioJitterBufferMaxPackets,
184 _audioJitterBufferFastAccelerate,
185 _iceConnectionReceivingTimeout,
186 _iceBackupCandidatePairPingInterval,
187 _iceCandidatePoolSize,
188 _shouldPruneTurnPorts,
189 _shouldPresumeWritableWhenFullyRelayed,
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700190 _shouldSurfaceIceCandidatesOnIceTransportTypeChanged,
Steve Anton8cb344a2018-02-27 15:34:53 -0800191 _iceCheckMinInterval,
Steve Anton8cb344a2018-02-27 15:34:53 -0800192 _disableLinkLocalNetworks,
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300193 _disableIPV6,
194 _disableIPV6OnWiFi,
Zhi Huangb57e1692018-06-12 11:41:11 -0700195 _maxIPv6Networks,
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -0700196 _activeResetSrtpParams,
Yura Yaroshevich41736142021-03-16 18:04:36 +0300197 _enableDscp,
198 _enableImplicitRollback];
hjon6d49a8e2016-01-26 13:06:42 -0800199}
200
201#pragma mark - Private
202
hbosa73ca562016-05-17 03:28:58 -0700203- (webrtc::PeerConnectionInterface::RTCConfiguration *)
204 createNativeConfiguration {
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200205 std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration>
Honghai Zhangf7ddc062016-09-01 15:34:01 -0700206 nativeConfig(new webrtc::PeerConnectionInterface::RTCConfiguration(
207 webrtc::PeerConnectionInterface::RTCConfigurationType::kAggressive));
hjon6d49a8e2016-01-26 13:06:42 -0800208
Taylor Brandstetter21c80322020-03-24 15:41:19 -0700209 nativeConfig->set_dscp(_enableDscp);
Mirko Bonadeia81e9c82020-05-04 16:14:32 +0200210 for (RTC_OBJC_TYPE(RTCIceServer) * iceServer in _iceServers) {
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200211 nativeConfig->servers.push_back(iceServer.nativeServer);
hjon6d49a8e2016-01-26 13:06:42 -0800212 }
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200213 nativeConfig->type =
hjon6d49a8e2016-01-26 13:06:42 -0800214 [[self class] nativeTransportsTypeForTransportPolicy:_iceTransportPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200215 nativeConfig->bundle_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800216 [[self class] nativeBundlePolicyForPolicy:_bundlePolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200217 nativeConfig->rtcp_mux_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800218 [[self class] nativeRtcpMuxPolicyForPolicy:_rtcpMuxPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200219 nativeConfig->tcp_candidate_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800220 [[self class] nativeTcpCandidatePolicyForPolicy:_tcpCandidatePolicy];
Honghai Zhang46007ae2016-06-03 16:31:32 -0700221 nativeConfig->candidate_network_policy = [[self class]
222 nativeCandidateNetworkPolicyForPolicy:_candidateNetworkPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200223 nativeConfig->continual_gathering_policy = [[self class]
Honghai Zhang3108fc92016-05-11 10:10:39 -0700224 nativeContinualGatheringPolicyForPolicy:_continualGatheringPolicy];
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300225 nativeConfig->disable_ipv6 = _disableIPV6;
226 nativeConfig->disable_ipv6_on_wifi = _disableIPV6OnWiFi;
deadbeef2059bb32017-07-26 18:25:43 -0700227 nativeConfig->max_ipv6_networks = _maxIPv6Networks;
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100228 nativeConfig->disable_link_local_networks = _disableLinkLocalNetworks;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200229 nativeConfig->audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets;
hayscc9f95002016-12-05 14:24:32 -0800230 nativeConfig->audio_jitter_buffer_fast_accelerate =
231 _audioJitterBufferFastAccelerate ? true : false;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200232 nativeConfig->ice_connection_receiving_timeout =
hjon6d49a8e2016-01-26 13:06:42 -0800233 _iceConnectionReceivingTimeout;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200234 nativeConfig->ice_backup_candidate_pair_ping_interval =
hjon6d49a8e2016-01-26 13:06:42 -0800235 _iceBackupCandidatePairPingInterval;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200236 rtc::KeyType keyType =
237 [[self class] nativeEncryptionKeyTypeForKeyType:_keyType];
Michael Iedemaccee56b2018-07-05 15:28:24 +0200238 if (_certificate != nullptr) {
239 // if offered a pemcert use it...
240 RTC_LOG(LS_INFO) << "Have configured cert - using it.";
241 std::string pem_private_key = [[_certificate private_key] UTF8String];
242 std::string pem_certificate = [[_certificate certificate] UTF8String];
243 rtc::RTCCertificatePEM pem = rtc::RTCCertificatePEM(pem_private_key, pem_certificate);
244 rtc::scoped_refptr<rtc::RTCCertificate> certificate = rtc::RTCCertificate::FromPEM(pem);
245 RTC_LOG(LS_INFO) << "Created cert from PEM strings.";
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200246 if (!certificate) {
Michael Iedemaccee56b2018-07-05 15:28:24 +0200247 RTC_LOG(LS_ERROR) << "Failed to generate certificate from PEM.";
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200248 return nullptr;
tkchinab8f82f2016-01-27 17:50:11 -0800249 }
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200250 nativeConfig->certificates.push_back(certificate);
Michael Iedemaccee56b2018-07-05 15:28:24 +0200251 } else {
252 RTC_LOG(LS_INFO) << "Don't have configured cert.";
253 // Generate non-default certificate.
254 if (keyType != rtc::KT_DEFAULT) {
255 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
256 rtc::RTCCertificateGenerator::GenerateCertificate(rtc::KeyParams(keyType),
257 absl::optional<uint64_t>());
258 if (!certificate) {
259 RTCLogError(@"Failed to generate certificate.");
260 return nullptr;
261 }
262 nativeConfig->certificates.push_back(certificate);
263 }
tkchinab8f82f2016-01-27 17:50:11 -0800264 }
deadbeefbe0c96f2016-05-18 16:20:14 -0700265 nativeConfig->ice_candidate_pool_size = _iceCandidatePoolSize;
honghaizaf6b6e02016-07-11 15:09:26 -0700266 nativeConfig->prune_turn_ports = _shouldPruneTurnPorts ? true : false;
Taylor Brandstettere9851112016-07-01 11:11:13 -0700267 nativeConfig->presume_writable_when_fully_relayed =
honghaizaf6b6e02016-07-11 15:09:26 -0700268 _shouldPresumeWritableWhenFullyRelayed ? true : false;
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700269 nativeConfig->surface_ice_candidates_on_ice_transport_type_changed =
270 _shouldSurfaceIceCandidatesOnIceTransportTypeChanged ? true : false;
skvlada5d94ff2017-02-02 13:02:30 -0800271 if (_iceCheckMinInterval != nil) {
Danil Chapovalov196100e2018-06-21 10:17:24 +0200272 nativeConfig->ice_check_min_interval = absl::optional<int>(_iceCheckMinInterval.intValue);
skvlada5d94ff2017-02-02 13:02:30 -0800273 }
Steve Anton8cb344a2018-02-27 15:34:53 -0800274 nativeConfig->sdp_semantics = [[self class] nativeSdpSemanticsForSdpSemantics:_sdpSemantics];
Zeke Chinef1140e2017-10-27 15:42:08 -0700275 if (_turnCustomizer) {
276 nativeConfig->turn_customizer = _turnCustomizer;
277 }
Zhi Huangb57e1692018-06-12 11:41:11 -0700278 nativeConfig->active_reset_srtp_params = _activeResetSrtpParams ? true : false;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700279 if (_cryptoOptions) {
280 webrtc::CryptoOptions nativeCryptoOptions;
281 nativeCryptoOptions.srtp.enable_gcm_crypto_suites =
282 _cryptoOptions.srtpEnableGcmCryptoSuites ? true : false;
283 nativeCryptoOptions.srtp.enable_aes128_sha1_32_crypto_cipher =
284 _cryptoOptions.srtpEnableAes128Sha1_32CryptoCipher ? true : false;
285 nativeCryptoOptions.srtp.enable_encrypted_rtp_header_extensions =
286 _cryptoOptions.srtpEnableEncryptedRtpHeaderExtensions ? true : false;
287 nativeCryptoOptions.sframe.require_frame_encryption =
288 _cryptoOptions.sframeRequireFrameEncryption ? true : false;
289 nativeConfig->crypto_options = absl::optional<webrtc::CryptoOptions>(nativeCryptoOptions);
290 }
Brad Pughf24143d2020-11-16 16:27:20 -0800291 nativeConfig->turn_logging_id = [_turnLoggingId UTF8String];
Jiawei Oub1e47752018-11-13 23:48:19 -0800292 nativeConfig->set_audio_rtcp_report_interval_ms(_rtcpAudioReportIntervalMs);
293 nativeConfig->set_video_rtcp_report_interval_ms(_rtcpVideoReportIntervalMs);
philipel3eb84f02019-11-11 12:57:44 +0100294 nativeConfig->allow_codec_switching = _allowCodecSwitching;
Yura Yaroshevich41736142021-03-16 18:04:36 +0300295 nativeConfig->enable_implicit_rollback = _enableImplicitRollback;
Yura Yaroshevichcbadb8b2021-03-17 17:39:52 +0300296 nativeConfig->offer_extmap_allow_mixed = _offerExtmapAllowMixed;
Yura Yaroshevichb9fa3192021-03-31 16:48:39 +0300297 if (_iceCheckIntervalStrongConnectivity != nil) {
298 nativeConfig->ice_check_interval_strong_connectivity =
299 absl::optional<int>(_iceCheckIntervalStrongConnectivity.intValue);
300 }
301 if (_iceCheckIntervalWeakConnectivity != nil) {
302 nativeConfig->ice_check_interval_weak_connectivity =
303 absl::optional<int>(_iceCheckIntervalWeakConnectivity.intValue);
304 }
305 if (_iceUnwritableTimeout != nil) {
306 nativeConfig->ice_unwritable_timeout = absl::optional<int>(_iceUnwritableTimeout.intValue);
307 }
308 if (_iceUnwritableMinChecks != nil) {
309 nativeConfig->ice_unwritable_min_checks = absl::optional<int>(_iceUnwritableMinChecks.intValue);
310 }
311 if (_iceInactiveTimeout != nil) {
312 nativeConfig->ice_inactive_timeout = absl::optional<int>(_iceInactiveTimeout.intValue);
313 }
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200314 return nativeConfig.release();
hjon6d49a8e2016-01-26 13:06:42 -0800315}
316
hjon6d49a8e2016-01-26 13:06:42 -0800317+ (webrtc::PeerConnectionInterface::IceTransportsType)
318 nativeTransportsTypeForTransportPolicy:(RTCIceTransportPolicy)policy {
319 switch (policy) {
320 case RTCIceTransportPolicyNone:
321 return webrtc::PeerConnectionInterface::kNone;
322 case RTCIceTransportPolicyRelay:
323 return webrtc::PeerConnectionInterface::kRelay;
324 case RTCIceTransportPolicyNoHost:
325 return webrtc::PeerConnectionInterface::kNoHost;
326 case RTCIceTransportPolicyAll:
327 return webrtc::PeerConnectionInterface::kAll;
328 }
329}
330
331+ (RTCIceTransportPolicy)transportPolicyForTransportsType:
332 (webrtc::PeerConnectionInterface::IceTransportsType)nativeType {
333 switch (nativeType) {
334 case webrtc::PeerConnectionInterface::kNone:
335 return RTCIceTransportPolicyNone;
336 case webrtc::PeerConnectionInterface::kRelay:
337 return RTCIceTransportPolicyRelay;
338 case webrtc::PeerConnectionInterface::kNoHost:
339 return RTCIceTransportPolicyNoHost;
340 case webrtc::PeerConnectionInterface::kAll:
341 return RTCIceTransportPolicyAll;
342 }
343}
344
345+ (NSString *)stringForTransportPolicy:(RTCIceTransportPolicy)policy {
346 switch (policy) {
347 case RTCIceTransportPolicyNone:
348 return @"NONE";
349 case RTCIceTransportPolicyRelay:
350 return @"RELAY";
351 case RTCIceTransportPolicyNoHost:
352 return @"NO_HOST";
353 case RTCIceTransportPolicyAll:
354 return @"ALL";
355 }
356}
357
358+ (webrtc::PeerConnectionInterface::BundlePolicy)nativeBundlePolicyForPolicy:
359 (RTCBundlePolicy)policy {
360 switch (policy) {
361 case RTCBundlePolicyBalanced:
362 return webrtc::PeerConnectionInterface::kBundlePolicyBalanced;
363 case RTCBundlePolicyMaxCompat:
364 return webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat;
365 case RTCBundlePolicyMaxBundle:
366 return webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle;
367 }
368}
369
370+ (RTCBundlePolicy)bundlePolicyForNativePolicy:
371 (webrtc::PeerConnectionInterface::BundlePolicy)nativePolicy {
372 switch (nativePolicy) {
373 case webrtc::PeerConnectionInterface::kBundlePolicyBalanced:
374 return RTCBundlePolicyBalanced;
375 case webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat:
376 return RTCBundlePolicyMaxCompat;
377 case webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle:
378 return RTCBundlePolicyMaxBundle;
379 }
380}
381
382+ (NSString *)stringForBundlePolicy:(RTCBundlePolicy)policy {
383 switch (policy) {
384 case RTCBundlePolicyBalanced:
385 return @"BALANCED";
386 case RTCBundlePolicyMaxCompat:
387 return @"MAX_COMPAT";
388 case RTCBundlePolicyMaxBundle:
389 return @"MAX_BUNDLE";
390 }
391}
392
393+ (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativeRtcpMuxPolicyForPolicy:
394 (RTCRtcpMuxPolicy)policy {
395 switch (policy) {
396 case RTCRtcpMuxPolicyNegotiate:
397 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
398 case RTCRtcpMuxPolicyRequire:
399 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire;
400 }
401}
402
403+ (RTCRtcpMuxPolicy)rtcpMuxPolicyForNativePolicy:
404 (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativePolicy {
405 switch (nativePolicy) {
406 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate:
407 return RTCRtcpMuxPolicyNegotiate;
408 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire:
409 return RTCRtcpMuxPolicyRequire;
410 }
411}
412
413+ (NSString *)stringForRtcpMuxPolicy:(RTCRtcpMuxPolicy)policy {
414 switch (policy) {
415 case RTCRtcpMuxPolicyNegotiate:
416 return @"NEGOTIATE";
417 case RTCRtcpMuxPolicyRequire:
418 return @"REQUIRE";
419 }
420}
421
422+ (webrtc::PeerConnectionInterface::TcpCandidatePolicy)
423 nativeTcpCandidatePolicyForPolicy:(RTCTcpCandidatePolicy)policy {
424 switch (policy) {
425 case RTCTcpCandidatePolicyEnabled:
426 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled;
427 case RTCTcpCandidatePolicyDisabled:
428 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled;
429 }
430}
431
Honghai Zhang46007ae2016-06-03 16:31:32 -0700432+ (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)
433 nativeCandidateNetworkPolicyForPolicy:(RTCCandidateNetworkPolicy)policy {
434 switch (policy) {
435 case RTCCandidateNetworkPolicyAll:
436 return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll;
437 case RTCCandidateNetworkPolicyLowCost:
438 return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
439 }
440}
441
hjon6d49a8e2016-01-26 13:06:42 -0800442+ (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativePolicy:
443 (webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativePolicy {
444 switch (nativePolicy) {
445 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled:
446 return RTCTcpCandidatePolicyEnabled;
447 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled:
448 return RTCTcpCandidatePolicyDisabled;
449 }
450}
451
452+ (NSString *)stringForTcpCandidatePolicy:(RTCTcpCandidatePolicy)policy {
453 switch (policy) {
454 case RTCTcpCandidatePolicyEnabled:
455 return @"TCP_ENABLED";
456 case RTCTcpCandidatePolicyDisabled:
457 return @"TCP_DISABLED";
458 }
459}
460
Honghai Zhang46007ae2016-06-03 16:31:32 -0700461+ (RTCCandidateNetworkPolicy)candidateNetworkPolicyForNativePolicy:
462 (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)nativePolicy {
463 switch (nativePolicy) {
464 case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll:
465 return RTCCandidateNetworkPolicyAll;
466 case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost:
467 return RTCCandidateNetworkPolicyLowCost;
468 }
469}
470
471+ (NSString *)stringForCandidateNetworkPolicy:
472 (RTCCandidateNetworkPolicy)policy {
473 switch (policy) {
474 case RTCCandidateNetworkPolicyAll:
475 return @"CANDIDATE_ALL_NETWORKS";
476 case RTCCandidateNetworkPolicyLowCost:
477 return @"CANDIDATE_LOW_COST_NETWORKS";
478 }
479}
480
Honghai Zhang3108fc92016-05-11 10:10:39 -0700481+ (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)
482 nativeContinualGatheringPolicyForPolicy:
483 (RTCContinualGatheringPolicy)policy {
484 switch (policy) {
485 case RTCContinualGatheringPolicyGatherOnce:
486 return webrtc::PeerConnectionInterface::GATHER_ONCE;
487 case RTCContinualGatheringPolicyGatherContinually:
488 return webrtc::PeerConnectionInterface::GATHER_CONTINUALLY;
489 }
490}
491
492+ (RTCContinualGatheringPolicy)continualGatheringPolicyForNativePolicy:
493 (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)nativePolicy {
494 switch (nativePolicy) {
495 case webrtc::PeerConnectionInterface::GATHER_ONCE:
496 return RTCContinualGatheringPolicyGatherOnce;
497 case webrtc::PeerConnectionInterface::GATHER_CONTINUALLY:
498 return RTCContinualGatheringPolicyGatherContinually;
499 }
500}
501
502+ (NSString *)stringForContinualGatheringPolicy:
503 (RTCContinualGatheringPolicy)policy {
504 switch (policy) {
505 case RTCContinualGatheringPolicyGatherOnce:
506 return @"GATHER_ONCE";
507 case RTCContinualGatheringPolicyGatherContinually:
508 return @"GATHER_CONTINUALLY";
509 }
510}
511
hbosf9da44d2016-06-09 03:18:28 -0700512+ (rtc::KeyType)nativeEncryptionKeyTypeForKeyType:
513 (RTCEncryptionKeyType)keyType {
514 switch (keyType) {
515 case RTCEncryptionKeyTypeRSA:
516 return rtc::KT_RSA;
517 case RTCEncryptionKeyTypeECDSA:
518 return rtc::KT_ECDSA;
519 }
520}
521
Steve Anton8cb344a2018-02-27 15:34:53 -0800522+ (webrtc::SdpSemantics)nativeSdpSemanticsForSdpSemantics:(RTCSdpSemantics)sdpSemantics {
523 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800524 case RTCSdpSemanticsPlanB:
Harald Alvestrandfa67aef2021-12-08 14:30:55 +0000525 return webrtc::SdpSemantics::kPlanB_DEPRECATED;
Steve Anton8cb344a2018-02-27 15:34:53 -0800526 case RTCSdpSemanticsUnifiedPlan:
527 return webrtc::SdpSemantics::kUnifiedPlan;
528 }
529}
530
531+ (RTCSdpSemantics)sdpSemanticsForNativeSdpSemantics:(webrtc::SdpSemantics)sdpSemantics {
532 switch (sdpSemantics) {
Harald Alvestrandfa67aef2021-12-08 14:30:55 +0000533 case webrtc::SdpSemantics::kPlanB_DEPRECATED:
Steve Anton8cb344a2018-02-27 15:34:53 -0800534 return RTCSdpSemanticsPlanB;
535 case webrtc::SdpSemantics::kUnifiedPlan:
536 return RTCSdpSemanticsUnifiedPlan;
537 }
538}
539
540+ (NSString *)stringForSdpSemantics:(RTCSdpSemantics)sdpSemantics {
541 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800542 case RTCSdpSemanticsPlanB:
543 return @"PLAN_B";
544 case RTCSdpSemanticsUnifiedPlan:
545 return @"UNIFIED_PLAN";
546 }
547}
548
hjon6d49a8e2016-01-26 13:06:42 -0800549@end