blob: 5164a3c969f92eca1d2ca4b2bc6ae5088cc72c1e [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;
hjon6d49a8e2016-01-26 13:06:42 -080060
61- (instancetype)init {
jtteh4eeb5372017-04-03 15:06:37 -070062 // Copy defaults.
Yuriy Pavlyshak8cec4fb2018-09-07 16:43:31 +020063 webrtc::PeerConnectionInterface::RTCConfiguration config;
jtteh465faf02017-04-04 14:00:16 -070064 return [self initWithNativeConfiguration:config];
jtteh4eeb5372017-04-03 15:06:37 -070065}
66
67- (instancetype)initWithNativeConfiguration:
jtteh465faf02017-04-04 14:00:16 -070068 (const webrtc::PeerConnectionInterface::RTCConfiguration &)config {
hjon6d49a8e2016-01-26 13:06:42 -080069 if (self = [super init]) {
Taylor Brandstetter21c80322020-03-24 15:41:19 -070070 _enableDscp = config.dscp();
jtteh4eeb5372017-04-03 15:06:37 -070071 NSMutableArray *iceServers = [NSMutableArray array];
jtteh465faf02017-04-04 14:00:16 -070072 for (const webrtc::PeerConnectionInterface::IceServer& server : config.servers) {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020073 RTC_OBJC_TYPE(RTCIceServer) *iceServer =
74 [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithNativeServer:server];
jtteh4eeb5372017-04-03 15:06:37 -070075 [iceServers addObject:iceServer];
76 }
77 _iceServers = iceServers;
Michael Iedemaccee56b2018-07-05 15:28:24 +020078 if (!config.certificates.empty()) {
79 rtc::scoped_refptr<rtc::RTCCertificate> native_cert;
80 native_cert = config.certificates[0];
81 rtc::RTCCertificatePEM native_pem = native_cert->ToPEM();
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020082 _certificate = [[RTC_OBJC_TYPE(RTCCertificate) alloc]
83 initWithPrivateKey:@(native_pem.private_key().c_str())
84 certificate:@(native_pem.certificate().c_str())];
Michael Iedemaccee56b2018-07-05 15:28:24 +020085 }
hjon6d49a8e2016-01-26 13:06:42 -080086 _iceTransportPolicy =
jtteh465faf02017-04-04 14:00:16 -070087 [[self class] transportPolicyForTransportsType:config.type];
hjon6d49a8e2016-01-26 13:06:42 -080088 _bundlePolicy =
jtteh465faf02017-04-04 14:00:16 -070089 [[self class] bundlePolicyForNativePolicy:config.bundle_policy];
hjon6d49a8e2016-01-26 13:06:42 -080090 _rtcpMuxPolicy =
jtteh465faf02017-04-04 14:00:16 -070091 [[self class] rtcpMuxPolicyForNativePolicy:config.rtcp_mux_policy];
hjon6d49a8e2016-01-26 13:06:42 -080092 _tcpCandidatePolicy = [[self class] tcpCandidatePolicyForNativePolicy:
jtteh465faf02017-04-04 14:00:16 -070093 config.tcp_candidate_policy];
Honghai Zhang46007ae2016-06-03 16:31:32 -070094 _candidateNetworkPolicy = [[self class]
jtteh465faf02017-04-04 14:00:16 -070095 candidateNetworkPolicyForNativePolicy:config.candidate_network_policy];
Honghai Zhang3108fc92016-05-11 10:10:39 -070096 webrtc::PeerConnectionInterface::ContinualGatheringPolicy nativePolicy =
jtteh465faf02017-04-04 14:00:16 -070097 config.continual_gathering_policy;
Honghai Zhang3108fc92016-05-11 10:10:39 -070098 _continualGatheringPolicy =
99 [[self class] continualGatheringPolicyForNativePolicy:nativePolicy];
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300100 _disableIPV6 = config.disable_ipv6;
101 _disableIPV6OnWiFi = config.disable_ipv6_on_wifi;
deadbeef2059bb32017-07-26 18:25:43 -0700102 _maxIPv6Networks = config.max_ipv6_networks;
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100103 _disableLinkLocalNetworks = config.disable_link_local_networks;
jtteh465faf02017-04-04 14:00:16 -0700104 _audioJitterBufferMaxPackets = config.audio_jitter_buffer_max_packets;
105 _audioJitterBufferFastAccelerate = config.audio_jitter_buffer_fast_accelerate;
106 _iceConnectionReceivingTimeout = config.ice_connection_receiving_timeout;
hjon6d49a8e2016-01-26 13:06:42 -0800107 _iceBackupCandidatePairPingInterval =
jtteh465faf02017-04-04 14:00:16 -0700108 config.ice_backup_candidate_pair_ping_interval;
tkchinab8f82f2016-01-27 17:50:11 -0800109 _keyType = RTCEncryptionKeyTypeECDSA;
jtteh465faf02017-04-04 14:00:16 -0700110 _iceCandidatePoolSize = config.ice_candidate_pool_size;
111 _shouldPruneTurnPorts = config.prune_turn_ports;
honghaizaf6b6e02016-07-11 15:09:26 -0700112 _shouldPresumeWritableWhenFullyRelayed =
jtteh465faf02017-04-04 14:00:16 -0700113 config.presume_writable_when_fully_relayed;
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700114 _shouldSurfaceIceCandidatesOnIceTransportTypeChanged =
115 config.surface_ice_candidates_on_ice_transport_type_changed;
jtteh465faf02017-04-04 14:00:16 -0700116 if (config.ice_check_min_interval) {
skvlada5d94ff2017-02-02 13:02:30 -0800117 _iceCheckMinInterval =
jtteh465faf02017-04-04 14:00:16 -0700118 [NSNumber numberWithInt:*config.ice_check_min_interval];
skvlada5d94ff2017-02-02 13:02:30 -0800119 }
Steve Anton8cb344a2018-02-27 15:34:53 -0800120 _sdpSemantics = [[self class] sdpSemanticsForNativeSdpSemantics:config.sdp_semantics];
Zeke Chinef1140e2017-10-27 15:42:08 -0700121 _turnCustomizer = config.turn_customizer;
Zhi Huangb57e1692018-06-12 11:41:11 -0700122 _activeResetSrtpParams = config.active_reset_srtp_params;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700123 if (config.crypto_options) {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +0200124 _cryptoOptions = [[RTC_OBJC_TYPE(RTCCryptoOptions) alloc]
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700125 initWithSrtpEnableGcmCryptoSuites:config.crypto_options->srtp
126 .enable_gcm_crypto_suites
127 srtpEnableAes128Sha1_32CryptoCipher:config.crypto_options->srtp
128 .enable_aes128_sha1_32_crypto_cipher
129 srtpEnableEncryptedRtpHeaderExtensions:config.crypto_options->srtp
130 .enable_encrypted_rtp_header_extensions
131 sframeRequireFrameEncryption:config.crypto_options->sframe
132 .require_frame_encryption];
133 }
Brad Pughf24143d2020-11-16 16:27:20 -0800134 _turnLoggingId = [NSString stringWithUTF8String:config.turn_logging_id.c_str()];
Jiawei Oub1e47752018-11-13 23:48:19 -0800135 _rtcpAudioReportIntervalMs = config.audio_rtcp_report_interval_ms();
136 _rtcpVideoReportIntervalMs = config.video_rtcp_report_interval_ms();
philipel3eb84f02019-11-11 12:57:44 +0100137 _allowCodecSwitching = config.allow_codec_switching.value_or(false);
Yura Yaroshevich41736142021-03-16 18:04:36 +0300138 _enableImplicitRollback = config.enable_implicit_rollback;
hjon6d49a8e2016-01-26 13:06:42 -0800139 }
140 return self;
141}
142
143- (NSString *)description {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +0200144 static NSString *formatString = @"RTC_OBJC_TYPE(RTCConfiguration): "
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300145 @"{\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%d\n%d\n%d\n%d\n%d\n%d\n"
Yura Yaroshevich41736142021-03-16 18:04:36 +0300146 @"%d\n%@\n%d\n%d\n%d\n%d\n%d\n%@\n%@\n}\n";
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100147
Steve Anton8cb344a2018-02-27 15:34:53 -0800148 return [NSString
149 stringWithFormat:formatString,
150 _iceServers,
151 [[self class] stringForTransportPolicy:_iceTransportPolicy],
152 [[self class] stringForBundlePolicy:_bundlePolicy],
153 [[self class] stringForRtcpMuxPolicy:_rtcpMuxPolicy],
154 [[self class] stringForTcpCandidatePolicy:_tcpCandidatePolicy],
155 [[self class] stringForCandidateNetworkPolicy:_candidateNetworkPolicy],
156 [[self class] stringForContinualGatheringPolicy:_continualGatheringPolicy],
157 [[self class] stringForSdpSemantics:_sdpSemantics],
158 _audioJitterBufferMaxPackets,
159 _audioJitterBufferFastAccelerate,
160 _iceConnectionReceivingTimeout,
161 _iceBackupCandidatePairPingInterval,
162 _iceCandidatePoolSize,
163 _shouldPruneTurnPorts,
164 _shouldPresumeWritableWhenFullyRelayed,
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700165 _shouldSurfaceIceCandidatesOnIceTransportTypeChanged,
Steve Anton8cb344a2018-02-27 15:34:53 -0800166 _iceCheckMinInterval,
Steve Anton8cb344a2018-02-27 15:34:53 -0800167 _disableLinkLocalNetworks,
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300168 _disableIPV6,
169 _disableIPV6OnWiFi,
Zhi Huangb57e1692018-06-12 11:41:11 -0700170 _maxIPv6Networks,
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -0700171 _activeResetSrtpParams,
Yura Yaroshevich41736142021-03-16 18:04:36 +0300172 _enableDscp,
173 _enableImplicitRollback];
hjon6d49a8e2016-01-26 13:06:42 -0800174}
175
176#pragma mark - Private
177
hbosa73ca562016-05-17 03:28:58 -0700178- (webrtc::PeerConnectionInterface::RTCConfiguration *)
179 createNativeConfiguration {
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200180 std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration>
Honghai Zhangf7ddc062016-09-01 15:34:01 -0700181 nativeConfig(new webrtc::PeerConnectionInterface::RTCConfiguration(
182 webrtc::PeerConnectionInterface::RTCConfigurationType::kAggressive));
hjon6d49a8e2016-01-26 13:06:42 -0800183
Taylor Brandstetter21c80322020-03-24 15:41:19 -0700184 nativeConfig->set_dscp(_enableDscp);
Mirko Bonadeia81e9c82020-05-04 16:14:32 +0200185 for (RTC_OBJC_TYPE(RTCIceServer) * iceServer in _iceServers) {
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200186 nativeConfig->servers.push_back(iceServer.nativeServer);
hjon6d49a8e2016-01-26 13:06:42 -0800187 }
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200188 nativeConfig->type =
hjon6d49a8e2016-01-26 13:06:42 -0800189 [[self class] nativeTransportsTypeForTransportPolicy:_iceTransportPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200190 nativeConfig->bundle_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800191 [[self class] nativeBundlePolicyForPolicy:_bundlePolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200192 nativeConfig->rtcp_mux_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800193 [[self class] nativeRtcpMuxPolicyForPolicy:_rtcpMuxPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200194 nativeConfig->tcp_candidate_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800195 [[self class] nativeTcpCandidatePolicyForPolicy:_tcpCandidatePolicy];
Honghai Zhang46007ae2016-06-03 16:31:32 -0700196 nativeConfig->candidate_network_policy = [[self class]
197 nativeCandidateNetworkPolicyForPolicy:_candidateNetworkPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200198 nativeConfig->continual_gathering_policy = [[self class]
Honghai Zhang3108fc92016-05-11 10:10:39 -0700199 nativeContinualGatheringPolicyForPolicy:_continualGatheringPolicy];
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300200 nativeConfig->disable_ipv6 = _disableIPV6;
201 nativeConfig->disable_ipv6_on_wifi = _disableIPV6OnWiFi;
deadbeef2059bb32017-07-26 18:25:43 -0700202 nativeConfig->max_ipv6_networks = _maxIPv6Networks;
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100203 nativeConfig->disable_link_local_networks = _disableLinkLocalNetworks;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200204 nativeConfig->audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets;
hayscc9f95002016-12-05 14:24:32 -0800205 nativeConfig->audio_jitter_buffer_fast_accelerate =
206 _audioJitterBufferFastAccelerate ? true : false;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200207 nativeConfig->ice_connection_receiving_timeout =
hjon6d49a8e2016-01-26 13:06:42 -0800208 _iceConnectionReceivingTimeout;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200209 nativeConfig->ice_backup_candidate_pair_ping_interval =
hjon6d49a8e2016-01-26 13:06:42 -0800210 _iceBackupCandidatePairPingInterval;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200211 rtc::KeyType keyType =
212 [[self class] nativeEncryptionKeyTypeForKeyType:_keyType];
Michael Iedemaccee56b2018-07-05 15:28:24 +0200213 if (_certificate != nullptr) {
214 // if offered a pemcert use it...
215 RTC_LOG(LS_INFO) << "Have configured cert - using it.";
216 std::string pem_private_key = [[_certificate private_key] UTF8String];
217 std::string pem_certificate = [[_certificate certificate] UTF8String];
218 rtc::RTCCertificatePEM pem = rtc::RTCCertificatePEM(pem_private_key, pem_certificate);
219 rtc::scoped_refptr<rtc::RTCCertificate> certificate = rtc::RTCCertificate::FromPEM(pem);
220 RTC_LOG(LS_INFO) << "Created cert from PEM strings.";
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200221 if (!certificate) {
Michael Iedemaccee56b2018-07-05 15:28:24 +0200222 RTC_LOG(LS_ERROR) << "Failed to generate certificate from PEM.";
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200223 return nullptr;
tkchinab8f82f2016-01-27 17:50:11 -0800224 }
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200225 nativeConfig->certificates.push_back(certificate);
Michael Iedemaccee56b2018-07-05 15:28:24 +0200226 } else {
227 RTC_LOG(LS_INFO) << "Don't have configured cert.";
228 // Generate non-default certificate.
229 if (keyType != rtc::KT_DEFAULT) {
230 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
231 rtc::RTCCertificateGenerator::GenerateCertificate(rtc::KeyParams(keyType),
232 absl::optional<uint64_t>());
233 if (!certificate) {
234 RTCLogError(@"Failed to generate certificate.");
235 return nullptr;
236 }
237 nativeConfig->certificates.push_back(certificate);
238 }
tkchinab8f82f2016-01-27 17:50:11 -0800239 }
deadbeefbe0c96f2016-05-18 16:20:14 -0700240 nativeConfig->ice_candidate_pool_size = _iceCandidatePoolSize;
honghaizaf6b6e02016-07-11 15:09:26 -0700241 nativeConfig->prune_turn_ports = _shouldPruneTurnPorts ? true : false;
Taylor Brandstettere9851112016-07-01 11:11:13 -0700242 nativeConfig->presume_writable_when_fully_relayed =
honghaizaf6b6e02016-07-11 15:09:26 -0700243 _shouldPresumeWritableWhenFullyRelayed ? true : false;
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700244 nativeConfig->surface_ice_candidates_on_ice_transport_type_changed =
245 _shouldSurfaceIceCandidatesOnIceTransportTypeChanged ? true : false;
skvlada5d94ff2017-02-02 13:02:30 -0800246 if (_iceCheckMinInterval != nil) {
Danil Chapovalov196100e2018-06-21 10:17:24 +0200247 nativeConfig->ice_check_min_interval = absl::optional<int>(_iceCheckMinInterval.intValue);
skvlada5d94ff2017-02-02 13:02:30 -0800248 }
Steve Anton8cb344a2018-02-27 15:34:53 -0800249 nativeConfig->sdp_semantics = [[self class] nativeSdpSemanticsForSdpSemantics:_sdpSemantics];
Zeke Chinef1140e2017-10-27 15:42:08 -0700250 if (_turnCustomizer) {
251 nativeConfig->turn_customizer = _turnCustomizer;
252 }
Zhi Huangb57e1692018-06-12 11:41:11 -0700253 nativeConfig->active_reset_srtp_params = _activeResetSrtpParams ? true : false;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700254 if (_cryptoOptions) {
255 webrtc::CryptoOptions nativeCryptoOptions;
256 nativeCryptoOptions.srtp.enable_gcm_crypto_suites =
257 _cryptoOptions.srtpEnableGcmCryptoSuites ? true : false;
258 nativeCryptoOptions.srtp.enable_aes128_sha1_32_crypto_cipher =
259 _cryptoOptions.srtpEnableAes128Sha1_32CryptoCipher ? true : false;
260 nativeCryptoOptions.srtp.enable_encrypted_rtp_header_extensions =
261 _cryptoOptions.srtpEnableEncryptedRtpHeaderExtensions ? true : false;
262 nativeCryptoOptions.sframe.require_frame_encryption =
263 _cryptoOptions.sframeRequireFrameEncryption ? true : false;
264 nativeConfig->crypto_options = absl::optional<webrtc::CryptoOptions>(nativeCryptoOptions);
265 }
Brad Pughf24143d2020-11-16 16:27:20 -0800266 nativeConfig->turn_logging_id = [_turnLoggingId UTF8String];
Jiawei Oub1e47752018-11-13 23:48:19 -0800267 nativeConfig->set_audio_rtcp_report_interval_ms(_rtcpAudioReportIntervalMs);
268 nativeConfig->set_video_rtcp_report_interval_ms(_rtcpVideoReportIntervalMs);
philipel3eb84f02019-11-11 12:57:44 +0100269 nativeConfig->allow_codec_switching = _allowCodecSwitching;
Yura Yaroshevich41736142021-03-16 18:04:36 +0300270 nativeConfig->enable_implicit_rollback = _enableImplicitRollback;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200271 return nativeConfig.release();
hjon6d49a8e2016-01-26 13:06:42 -0800272}
273
hjon6d49a8e2016-01-26 13:06:42 -0800274+ (webrtc::PeerConnectionInterface::IceTransportsType)
275 nativeTransportsTypeForTransportPolicy:(RTCIceTransportPolicy)policy {
276 switch (policy) {
277 case RTCIceTransportPolicyNone:
278 return webrtc::PeerConnectionInterface::kNone;
279 case RTCIceTransportPolicyRelay:
280 return webrtc::PeerConnectionInterface::kRelay;
281 case RTCIceTransportPolicyNoHost:
282 return webrtc::PeerConnectionInterface::kNoHost;
283 case RTCIceTransportPolicyAll:
284 return webrtc::PeerConnectionInterface::kAll;
285 }
286}
287
288+ (RTCIceTransportPolicy)transportPolicyForTransportsType:
289 (webrtc::PeerConnectionInterface::IceTransportsType)nativeType {
290 switch (nativeType) {
291 case webrtc::PeerConnectionInterface::kNone:
292 return RTCIceTransportPolicyNone;
293 case webrtc::PeerConnectionInterface::kRelay:
294 return RTCIceTransportPolicyRelay;
295 case webrtc::PeerConnectionInterface::kNoHost:
296 return RTCIceTransportPolicyNoHost;
297 case webrtc::PeerConnectionInterface::kAll:
298 return RTCIceTransportPolicyAll;
299 }
300}
301
302+ (NSString *)stringForTransportPolicy:(RTCIceTransportPolicy)policy {
303 switch (policy) {
304 case RTCIceTransportPolicyNone:
305 return @"NONE";
306 case RTCIceTransportPolicyRelay:
307 return @"RELAY";
308 case RTCIceTransportPolicyNoHost:
309 return @"NO_HOST";
310 case RTCIceTransportPolicyAll:
311 return @"ALL";
312 }
313}
314
315+ (webrtc::PeerConnectionInterface::BundlePolicy)nativeBundlePolicyForPolicy:
316 (RTCBundlePolicy)policy {
317 switch (policy) {
318 case RTCBundlePolicyBalanced:
319 return webrtc::PeerConnectionInterface::kBundlePolicyBalanced;
320 case RTCBundlePolicyMaxCompat:
321 return webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat;
322 case RTCBundlePolicyMaxBundle:
323 return webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle;
324 }
325}
326
327+ (RTCBundlePolicy)bundlePolicyForNativePolicy:
328 (webrtc::PeerConnectionInterface::BundlePolicy)nativePolicy {
329 switch (nativePolicy) {
330 case webrtc::PeerConnectionInterface::kBundlePolicyBalanced:
331 return RTCBundlePolicyBalanced;
332 case webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat:
333 return RTCBundlePolicyMaxCompat;
334 case webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle:
335 return RTCBundlePolicyMaxBundle;
336 }
337}
338
339+ (NSString *)stringForBundlePolicy:(RTCBundlePolicy)policy {
340 switch (policy) {
341 case RTCBundlePolicyBalanced:
342 return @"BALANCED";
343 case RTCBundlePolicyMaxCompat:
344 return @"MAX_COMPAT";
345 case RTCBundlePolicyMaxBundle:
346 return @"MAX_BUNDLE";
347 }
348}
349
350+ (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativeRtcpMuxPolicyForPolicy:
351 (RTCRtcpMuxPolicy)policy {
352 switch (policy) {
353 case RTCRtcpMuxPolicyNegotiate:
354 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
355 case RTCRtcpMuxPolicyRequire:
356 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire;
357 }
358}
359
360+ (RTCRtcpMuxPolicy)rtcpMuxPolicyForNativePolicy:
361 (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativePolicy {
362 switch (nativePolicy) {
363 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate:
364 return RTCRtcpMuxPolicyNegotiate;
365 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire:
366 return RTCRtcpMuxPolicyRequire;
367 }
368}
369
370+ (NSString *)stringForRtcpMuxPolicy:(RTCRtcpMuxPolicy)policy {
371 switch (policy) {
372 case RTCRtcpMuxPolicyNegotiate:
373 return @"NEGOTIATE";
374 case RTCRtcpMuxPolicyRequire:
375 return @"REQUIRE";
376 }
377}
378
379+ (webrtc::PeerConnectionInterface::TcpCandidatePolicy)
380 nativeTcpCandidatePolicyForPolicy:(RTCTcpCandidatePolicy)policy {
381 switch (policy) {
382 case RTCTcpCandidatePolicyEnabled:
383 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled;
384 case RTCTcpCandidatePolicyDisabled:
385 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled;
386 }
387}
388
Honghai Zhang46007ae2016-06-03 16:31:32 -0700389+ (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)
390 nativeCandidateNetworkPolicyForPolicy:(RTCCandidateNetworkPolicy)policy {
391 switch (policy) {
392 case RTCCandidateNetworkPolicyAll:
393 return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll;
394 case RTCCandidateNetworkPolicyLowCost:
395 return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
396 }
397}
398
hjon6d49a8e2016-01-26 13:06:42 -0800399+ (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativePolicy:
400 (webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativePolicy {
401 switch (nativePolicy) {
402 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled:
403 return RTCTcpCandidatePolicyEnabled;
404 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled:
405 return RTCTcpCandidatePolicyDisabled;
406 }
407}
408
409+ (NSString *)stringForTcpCandidatePolicy:(RTCTcpCandidatePolicy)policy {
410 switch (policy) {
411 case RTCTcpCandidatePolicyEnabled:
412 return @"TCP_ENABLED";
413 case RTCTcpCandidatePolicyDisabled:
414 return @"TCP_DISABLED";
415 }
416}
417
Honghai Zhang46007ae2016-06-03 16:31:32 -0700418+ (RTCCandidateNetworkPolicy)candidateNetworkPolicyForNativePolicy:
419 (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)nativePolicy {
420 switch (nativePolicy) {
421 case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll:
422 return RTCCandidateNetworkPolicyAll;
423 case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost:
424 return RTCCandidateNetworkPolicyLowCost;
425 }
426}
427
428+ (NSString *)stringForCandidateNetworkPolicy:
429 (RTCCandidateNetworkPolicy)policy {
430 switch (policy) {
431 case RTCCandidateNetworkPolicyAll:
432 return @"CANDIDATE_ALL_NETWORKS";
433 case RTCCandidateNetworkPolicyLowCost:
434 return @"CANDIDATE_LOW_COST_NETWORKS";
435 }
436}
437
Honghai Zhang3108fc92016-05-11 10:10:39 -0700438+ (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)
439 nativeContinualGatheringPolicyForPolicy:
440 (RTCContinualGatheringPolicy)policy {
441 switch (policy) {
442 case RTCContinualGatheringPolicyGatherOnce:
443 return webrtc::PeerConnectionInterface::GATHER_ONCE;
444 case RTCContinualGatheringPolicyGatherContinually:
445 return webrtc::PeerConnectionInterface::GATHER_CONTINUALLY;
446 }
447}
448
449+ (RTCContinualGatheringPolicy)continualGatheringPolicyForNativePolicy:
450 (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)nativePolicy {
451 switch (nativePolicy) {
452 case webrtc::PeerConnectionInterface::GATHER_ONCE:
453 return RTCContinualGatheringPolicyGatherOnce;
454 case webrtc::PeerConnectionInterface::GATHER_CONTINUALLY:
455 return RTCContinualGatheringPolicyGatherContinually;
456 }
457}
458
459+ (NSString *)stringForContinualGatheringPolicy:
460 (RTCContinualGatheringPolicy)policy {
461 switch (policy) {
462 case RTCContinualGatheringPolicyGatherOnce:
463 return @"GATHER_ONCE";
464 case RTCContinualGatheringPolicyGatherContinually:
465 return @"GATHER_CONTINUALLY";
466 }
467}
468
hbosf9da44d2016-06-09 03:18:28 -0700469+ (rtc::KeyType)nativeEncryptionKeyTypeForKeyType:
470 (RTCEncryptionKeyType)keyType {
471 switch (keyType) {
472 case RTCEncryptionKeyTypeRSA:
473 return rtc::KT_RSA;
474 case RTCEncryptionKeyTypeECDSA:
475 return rtc::KT_ECDSA;
476 }
477}
478
Steve Anton8cb344a2018-02-27 15:34:53 -0800479+ (webrtc::SdpSemantics)nativeSdpSemanticsForSdpSemantics:(RTCSdpSemantics)sdpSemantics {
480 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800481 case RTCSdpSemanticsPlanB:
482 return webrtc::SdpSemantics::kPlanB;
483 case RTCSdpSemanticsUnifiedPlan:
484 return webrtc::SdpSemantics::kUnifiedPlan;
485 }
486}
487
488+ (RTCSdpSemantics)sdpSemanticsForNativeSdpSemantics:(webrtc::SdpSemantics)sdpSemantics {
489 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800490 case webrtc::SdpSemantics::kPlanB:
491 return RTCSdpSemanticsPlanB;
492 case webrtc::SdpSemantics::kUnifiedPlan:
493 return RTCSdpSemanticsUnifiedPlan;
494 }
495}
496
497+ (NSString *)stringForSdpSemantics:(RTCSdpSemantics)sdpSemantics {
498 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800499 case RTCSdpSemanticsPlanB:
500 return @"PLAN_B";
501 case RTCSdpSemanticsUnifiedPlan:
502 return @"UNIFIED_PLAN";
503 }
504}
505
hjon6d49a8e2016-01-26 13:06:42 -0800506@end