blob: d003eed1e340355ed0a1fb65d913dbd0bdb3bb3f [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;
hjon6d49a8e2016-01-26 13:06:42 -080061
62- (instancetype)init {
jtteh4eeb5372017-04-03 15:06:37 -070063 // Copy defaults.
Yuriy Pavlyshak8cec4fb2018-09-07 16:43:31 +020064 webrtc::PeerConnectionInterface::RTCConfiguration config;
jtteh465faf02017-04-04 14:00:16 -070065 return [self initWithNativeConfiguration:config];
jtteh4eeb5372017-04-03 15:06:37 -070066}
67
68- (instancetype)initWithNativeConfiguration:
jtteh465faf02017-04-04 14:00:16 -070069 (const webrtc::PeerConnectionInterface::RTCConfiguration &)config {
hjon6d49a8e2016-01-26 13:06:42 -080070 if (self = [super init]) {
Taylor Brandstetter21c80322020-03-24 15:41:19 -070071 _enableDscp = config.dscp();
jtteh4eeb5372017-04-03 15:06:37 -070072 NSMutableArray *iceServers = [NSMutableArray array];
jtteh465faf02017-04-04 14:00:16 -070073 for (const webrtc::PeerConnectionInterface::IceServer& server : config.servers) {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020074 RTC_OBJC_TYPE(RTCIceServer) *iceServer =
75 [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithNativeServer:server];
jtteh4eeb5372017-04-03 15:06:37 -070076 [iceServers addObject:iceServer];
77 }
78 _iceServers = iceServers;
Michael Iedemaccee56b2018-07-05 15:28:24 +020079 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 Bonadeia81e9c82020-05-04 16:14:32 +020083 _certificate = [[RTC_OBJC_TYPE(RTCCertificate) alloc]
84 initWithPrivateKey:@(native_pem.private_key().c_str())
85 certificate:@(native_pem.certificate().c_str())];
Michael Iedemaccee56b2018-07-05 15:28:24 +020086 }
hjon6d49a8e2016-01-26 13:06:42 -080087 _iceTransportPolicy =
jtteh465faf02017-04-04 14:00:16 -070088 [[self class] transportPolicyForTransportsType:config.type];
hjon6d49a8e2016-01-26 13:06:42 -080089 _bundlePolicy =
jtteh465faf02017-04-04 14:00:16 -070090 [[self class] bundlePolicyForNativePolicy:config.bundle_policy];
hjon6d49a8e2016-01-26 13:06:42 -080091 _rtcpMuxPolicy =
jtteh465faf02017-04-04 14:00:16 -070092 [[self class] rtcpMuxPolicyForNativePolicy:config.rtcp_mux_policy];
hjon6d49a8e2016-01-26 13:06:42 -080093 _tcpCandidatePolicy = [[self class] tcpCandidatePolicyForNativePolicy:
jtteh465faf02017-04-04 14:00:16 -070094 config.tcp_candidate_policy];
Honghai Zhang46007ae2016-06-03 16:31:32 -070095 _candidateNetworkPolicy = [[self class]
jtteh465faf02017-04-04 14:00:16 -070096 candidateNetworkPolicyForNativePolicy:config.candidate_network_policy];
Honghai Zhang3108fc92016-05-11 10:10:39 -070097 webrtc::PeerConnectionInterface::ContinualGatheringPolicy nativePolicy =
jtteh465faf02017-04-04 14:00:16 -070098 config.continual_gathering_policy;
Honghai Zhang3108fc92016-05-11 10:10:39 -070099 _continualGatheringPolicy =
100 [[self class] continualGatheringPolicyForNativePolicy:nativePolicy];
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300101 _disableIPV6 = config.disable_ipv6;
102 _disableIPV6OnWiFi = config.disable_ipv6_on_wifi;
deadbeef2059bb32017-07-26 18:25:43 -0700103 _maxIPv6Networks = config.max_ipv6_networks;
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100104 _disableLinkLocalNetworks = config.disable_link_local_networks;
jtteh465faf02017-04-04 14:00:16 -0700105 _audioJitterBufferMaxPackets = config.audio_jitter_buffer_max_packets;
106 _audioJitterBufferFastAccelerate = config.audio_jitter_buffer_fast_accelerate;
107 _iceConnectionReceivingTimeout = config.ice_connection_receiving_timeout;
hjon6d49a8e2016-01-26 13:06:42 -0800108 _iceBackupCandidatePairPingInterval =
jtteh465faf02017-04-04 14:00:16 -0700109 config.ice_backup_candidate_pair_ping_interval;
tkchinab8f82f2016-01-27 17:50:11 -0800110 _keyType = RTCEncryptionKeyTypeECDSA;
jtteh465faf02017-04-04 14:00:16 -0700111 _iceCandidatePoolSize = config.ice_candidate_pool_size;
112 _shouldPruneTurnPorts = config.prune_turn_ports;
honghaizaf6b6e02016-07-11 15:09:26 -0700113 _shouldPresumeWritableWhenFullyRelayed =
jtteh465faf02017-04-04 14:00:16 -0700114 config.presume_writable_when_fully_relayed;
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700115 _shouldSurfaceIceCandidatesOnIceTransportTypeChanged =
116 config.surface_ice_candidates_on_ice_transport_type_changed;
jtteh465faf02017-04-04 14:00:16 -0700117 if (config.ice_check_min_interval) {
skvlada5d94ff2017-02-02 13:02:30 -0800118 _iceCheckMinInterval =
jtteh465faf02017-04-04 14:00:16 -0700119 [NSNumber numberWithInt:*config.ice_check_min_interval];
skvlada5d94ff2017-02-02 13:02:30 -0800120 }
Steve Anton8cb344a2018-02-27 15:34:53 -0800121 _sdpSemantics = [[self class] sdpSemanticsForNativeSdpSemantics:config.sdp_semantics];
Zeke Chinef1140e2017-10-27 15:42:08 -0700122 _turnCustomizer = config.turn_customizer;
Zhi Huangb57e1692018-06-12 11:41:11 -0700123 _activeResetSrtpParams = config.active_reset_srtp_params;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700124 if (config.crypto_options) {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +0200125 _cryptoOptions = [[RTC_OBJC_TYPE(RTCCryptoOptions) alloc]
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700126 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 Pughf24143d2020-11-16 16:27:20 -0800135 _turnLoggingId = [NSString stringWithUTF8String:config.turn_logging_id.c_str()];
Jiawei Oub1e47752018-11-13 23:48:19 -0800136 _rtcpAudioReportIntervalMs = config.audio_rtcp_report_interval_ms();
137 _rtcpVideoReportIntervalMs = config.video_rtcp_report_interval_ms();
philipel3eb84f02019-11-11 12:57:44 +0100138 _allowCodecSwitching = config.allow_codec_switching.value_or(false);
Yura Yaroshevich41736142021-03-16 18:04:36 +0300139 _enableImplicitRollback = config.enable_implicit_rollback;
Yura Yaroshevichcbadb8b2021-03-17 17:39:52 +0300140 _offerExtmapAllowMixed = config.offer_extmap_allow_mixed;
hjon6d49a8e2016-01-26 13:06:42 -0800141 }
142 return self;
143}
144
145- (NSString *)description {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +0200146 static NSString *formatString = @"RTC_OBJC_TYPE(RTCConfiguration): "
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300147 @"{\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 +0300148 @"%d\n%@\n%d\n%d\n%d\n%d\n%d\n%@\n%@\n}\n";
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100149
Steve Anton8cb344a2018-02-27 15:34:53 -0800150 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 Wang1fe119f2019-05-31 16:55:33 -0700167 _shouldSurfaceIceCandidatesOnIceTransportTypeChanged,
Steve Anton8cb344a2018-02-27 15:34:53 -0800168 _iceCheckMinInterval,
Steve Anton8cb344a2018-02-27 15:34:53 -0800169 _disableLinkLocalNetworks,
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300170 _disableIPV6,
171 _disableIPV6OnWiFi,
Zhi Huangb57e1692018-06-12 11:41:11 -0700172 _maxIPv6Networks,
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -0700173 _activeResetSrtpParams,
Yura Yaroshevich41736142021-03-16 18:04:36 +0300174 _enableDscp,
175 _enableImplicitRollback];
hjon6d49a8e2016-01-26 13:06:42 -0800176}
177
178#pragma mark - Private
179
hbosa73ca562016-05-17 03:28:58 -0700180- (webrtc::PeerConnectionInterface::RTCConfiguration *)
181 createNativeConfiguration {
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200182 std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration>
Honghai Zhangf7ddc062016-09-01 15:34:01 -0700183 nativeConfig(new webrtc::PeerConnectionInterface::RTCConfiguration(
184 webrtc::PeerConnectionInterface::RTCConfigurationType::kAggressive));
hjon6d49a8e2016-01-26 13:06:42 -0800185
Taylor Brandstetter21c80322020-03-24 15:41:19 -0700186 nativeConfig->set_dscp(_enableDscp);
Mirko Bonadeia81e9c82020-05-04 16:14:32 +0200187 for (RTC_OBJC_TYPE(RTCIceServer) * iceServer in _iceServers) {
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200188 nativeConfig->servers.push_back(iceServer.nativeServer);
hjon6d49a8e2016-01-26 13:06:42 -0800189 }
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200190 nativeConfig->type =
hjon6d49a8e2016-01-26 13:06:42 -0800191 [[self class] nativeTransportsTypeForTransportPolicy:_iceTransportPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200192 nativeConfig->bundle_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800193 [[self class] nativeBundlePolicyForPolicy:_bundlePolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200194 nativeConfig->rtcp_mux_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800195 [[self class] nativeRtcpMuxPolicyForPolicy:_rtcpMuxPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200196 nativeConfig->tcp_candidate_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800197 [[self class] nativeTcpCandidatePolicyForPolicy:_tcpCandidatePolicy];
Honghai Zhang46007ae2016-06-03 16:31:32 -0700198 nativeConfig->candidate_network_policy = [[self class]
199 nativeCandidateNetworkPolicyForPolicy:_candidateNetworkPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200200 nativeConfig->continual_gathering_policy = [[self class]
Honghai Zhang3108fc92016-05-11 10:10:39 -0700201 nativeContinualGatheringPolicyForPolicy:_continualGatheringPolicy];
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300202 nativeConfig->disable_ipv6 = _disableIPV6;
203 nativeConfig->disable_ipv6_on_wifi = _disableIPV6OnWiFi;
deadbeef2059bb32017-07-26 18:25:43 -0700204 nativeConfig->max_ipv6_networks = _maxIPv6Networks;
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100205 nativeConfig->disable_link_local_networks = _disableLinkLocalNetworks;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200206 nativeConfig->audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets;
hayscc9f95002016-12-05 14:24:32 -0800207 nativeConfig->audio_jitter_buffer_fast_accelerate =
208 _audioJitterBufferFastAccelerate ? true : false;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200209 nativeConfig->ice_connection_receiving_timeout =
hjon6d49a8e2016-01-26 13:06:42 -0800210 _iceConnectionReceivingTimeout;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200211 nativeConfig->ice_backup_candidate_pair_ping_interval =
hjon6d49a8e2016-01-26 13:06:42 -0800212 _iceBackupCandidatePairPingInterval;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200213 rtc::KeyType keyType =
214 [[self class] nativeEncryptionKeyTypeForKeyType:_keyType];
Michael Iedemaccee56b2018-07-05 15:28:24 +0200215 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öme06c2dd2016-05-13 13:50:38 +0200223 if (!certificate) {
Michael Iedemaccee56b2018-07-05 15:28:24 +0200224 RTC_LOG(LS_ERROR) << "Failed to generate certificate from PEM.";
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200225 return nullptr;
tkchinab8f82f2016-01-27 17:50:11 -0800226 }
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200227 nativeConfig->certificates.push_back(certificate);
Michael Iedemaccee56b2018-07-05 15:28:24 +0200228 } 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 }
tkchinab8f82f2016-01-27 17:50:11 -0800241 }
deadbeefbe0c96f2016-05-18 16:20:14 -0700242 nativeConfig->ice_candidate_pool_size = _iceCandidatePoolSize;
honghaizaf6b6e02016-07-11 15:09:26 -0700243 nativeConfig->prune_turn_ports = _shouldPruneTurnPorts ? true : false;
Taylor Brandstettere9851112016-07-01 11:11:13 -0700244 nativeConfig->presume_writable_when_fully_relayed =
honghaizaf6b6e02016-07-11 15:09:26 -0700245 _shouldPresumeWritableWhenFullyRelayed ? true : false;
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700246 nativeConfig->surface_ice_candidates_on_ice_transport_type_changed =
247 _shouldSurfaceIceCandidatesOnIceTransportTypeChanged ? true : false;
skvlada5d94ff2017-02-02 13:02:30 -0800248 if (_iceCheckMinInterval != nil) {
Danil Chapovalov196100e2018-06-21 10:17:24 +0200249 nativeConfig->ice_check_min_interval = absl::optional<int>(_iceCheckMinInterval.intValue);
skvlada5d94ff2017-02-02 13:02:30 -0800250 }
Steve Anton8cb344a2018-02-27 15:34:53 -0800251 nativeConfig->sdp_semantics = [[self class] nativeSdpSemanticsForSdpSemantics:_sdpSemantics];
Zeke Chinef1140e2017-10-27 15:42:08 -0700252 if (_turnCustomizer) {
253 nativeConfig->turn_customizer = _turnCustomizer;
254 }
Zhi Huangb57e1692018-06-12 11:41:11 -0700255 nativeConfig->active_reset_srtp_params = _activeResetSrtpParams ? true : false;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700256 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 Pughf24143d2020-11-16 16:27:20 -0800268 nativeConfig->turn_logging_id = [_turnLoggingId UTF8String];
Jiawei Oub1e47752018-11-13 23:48:19 -0800269 nativeConfig->set_audio_rtcp_report_interval_ms(_rtcpAudioReportIntervalMs);
270 nativeConfig->set_video_rtcp_report_interval_ms(_rtcpVideoReportIntervalMs);
philipel3eb84f02019-11-11 12:57:44 +0100271 nativeConfig->allow_codec_switching = _allowCodecSwitching;
Yura Yaroshevich41736142021-03-16 18:04:36 +0300272 nativeConfig->enable_implicit_rollback = _enableImplicitRollback;
Yura Yaroshevichcbadb8b2021-03-17 17:39:52 +0300273 nativeConfig->offer_extmap_allow_mixed = _offerExtmapAllowMixed;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200274 return nativeConfig.release();
hjon6d49a8e2016-01-26 13:06:42 -0800275}
276
hjon6d49a8e2016-01-26 13:06:42 -0800277+ (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 Zhang46007ae2016-06-03 16:31:32 -0700392+ (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
hjon6d49a8e2016-01-26 13:06:42 -0800402+ (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 Zhang46007ae2016-06-03 16:31:32 -0700421+ (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 Zhang3108fc92016-05-11 10:10:39 -0700441+ (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
hbosf9da44d2016-06-09 03:18:28 -0700472+ (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 Anton8cb344a2018-02-27 15:34:53 -0800482+ (webrtc::SdpSemantics)nativeSdpSemanticsForSdpSemantics:(RTCSdpSemantics)sdpSemantics {
483 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800484 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 Anton8cb344a2018-02-27 15:34:53 -0800493 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 Anton8cb344a2018-02-27 15:34:53 -0800502 case RTCSdpSemanticsPlanB:
503 return @"PLAN_B";
504 case RTCSdpSemanticsUnifiedPlan:
505 return @"UNIFIED_PLAN";
506 }
507}
508
hjon6d49a8e2016-01-26 13:06:42 -0800509@end