blob: a4af7febbcbe0245e93961473800fffdc1062b80 [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;
hjon6d49a8e2016-01-26 13:06:42 -080059
60- (instancetype)init {
jtteh4eeb5372017-04-03 15:06:37 -070061 // Copy defaults.
Yuriy Pavlyshak8cec4fb2018-09-07 16:43:31 +020062 webrtc::PeerConnectionInterface::RTCConfiguration config;
jtteh465faf02017-04-04 14:00:16 -070063 return [self initWithNativeConfiguration:config];
jtteh4eeb5372017-04-03 15:06:37 -070064}
65
66- (instancetype)initWithNativeConfiguration:
jtteh465faf02017-04-04 14:00:16 -070067 (const webrtc::PeerConnectionInterface::RTCConfiguration &)config {
hjon6d49a8e2016-01-26 13:06:42 -080068 if (self = [super init]) {
Taylor Brandstetter21c80322020-03-24 15:41:19 -070069 _enableDscp = config.dscp();
jtteh4eeb5372017-04-03 15:06:37 -070070 NSMutableArray *iceServers = [NSMutableArray array];
jtteh465faf02017-04-04 14:00:16 -070071 for (const webrtc::PeerConnectionInterface::IceServer& server : config.servers) {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020072 RTC_OBJC_TYPE(RTCIceServer) *iceServer =
73 [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithNativeServer:server];
jtteh4eeb5372017-04-03 15:06:37 -070074 [iceServers addObject:iceServer];
75 }
76 _iceServers = iceServers;
Michael Iedemaccee56b2018-07-05 15:28:24 +020077 if (!config.certificates.empty()) {
78 rtc::scoped_refptr<rtc::RTCCertificate> native_cert;
79 native_cert = config.certificates[0];
80 rtc::RTCCertificatePEM native_pem = native_cert->ToPEM();
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020081 _certificate = [[RTC_OBJC_TYPE(RTCCertificate) alloc]
82 initWithPrivateKey:@(native_pem.private_key().c_str())
83 certificate:@(native_pem.certificate().c_str())];
Michael Iedemaccee56b2018-07-05 15:28:24 +020084 }
hjon6d49a8e2016-01-26 13:06:42 -080085 _iceTransportPolicy =
jtteh465faf02017-04-04 14:00:16 -070086 [[self class] transportPolicyForTransportsType:config.type];
hjon6d49a8e2016-01-26 13:06:42 -080087 _bundlePolicy =
jtteh465faf02017-04-04 14:00:16 -070088 [[self class] bundlePolicyForNativePolicy:config.bundle_policy];
hjon6d49a8e2016-01-26 13:06:42 -080089 _rtcpMuxPolicy =
jtteh465faf02017-04-04 14:00:16 -070090 [[self class] rtcpMuxPolicyForNativePolicy:config.rtcp_mux_policy];
hjon6d49a8e2016-01-26 13:06:42 -080091 _tcpCandidatePolicy = [[self class] tcpCandidatePolicyForNativePolicy:
jtteh465faf02017-04-04 14:00:16 -070092 config.tcp_candidate_policy];
Honghai Zhang46007ae2016-06-03 16:31:32 -070093 _candidateNetworkPolicy = [[self class]
jtteh465faf02017-04-04 14:00:16 -070094 candidateNetworkPolicyForNativePolicy:config.candidate_network_policy];
Honghai Zhang3108fc92016-05-11 10:10:39 -070095 webrtc::PeerConnectionInterface::ContinualGatheringPolicy nativePolicy =
jtteh465faf02017-04-04 14:00:16 -070096 config.continual_gathering_policy;
Honghai Zhang3108fc92016-05-11 10:10:39 -070097 _continualGatheringPolicy =
98 [[self class] continualGatheringPolicyForNativePolicy:nativePolicy];
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +030099 _disableIPV6 = config.disable_ipv6;
100 _disableIPV6OnWiFi = config.disable_ipv6_on_wifi;
deadbeef2059bb32017-07-26 18:25:43 -0700101 _maxIPv6Networks = config.max_ipv6_networks;
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100102 _disableLinkLocalNetworks = config.disable_link_local_networks;
jtteh465faf02017-04-04 14:00:16 -0700103 _audioJitterBufferMaxPackets = config.audio_jitter_buffer_max_packets;
104 _audioJitterBufferFastAccelerate = config.audio_jitter_buffer_fast_accelerate;
105 _iceConnectionReceivingTimeout = config.ice_connection_receiving_timeout;
hjon6d49a8e2016-01-26 13:06:42 -0800106 _iceBackupCandidatePairPingInterval =
jtteh465faf02017-04-04 14:00:16 -0700107 config.ice_backup_candidate_pair_ping_interval;
tkchinab8f82f2016-01-27 17:50:11 -0800108 _keyType = RTCEncryptionKeyTypeECDSA;
jtteh465faf02017-04-04 14:00:16 -0700109 _iceCandidatePoolSize = config.ice_candidate_pool_size;
110 _shouldPruneTurnPorts = config.prune_turn_ports;
honghaizaf6b6e02016-07-11 15:09:26 -0700111 _shouldPresumeWritableWhenFullyRelayed =
jtteh465faf02017-04-04 14:00:16 -0700112 config.presume_writable_when_fully_relayed;
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700113 _shouldSurfaceIceCandidatesOnIceTransportTypeChanged =
114 config.surface_ice_candidates_on_ice_transport_type_changed;
jtteh465faf02017-04-04 14:00:16 -0700115 if (config.ice_check_min_interval) {
skvlada5d94ff2017-02-02 13:02:30 -0800116 _iceCheckMinInterval =
jtteh465faf02017-04-04 14:00:16 -0700117 [NSNumber numberWithInt:*config.ice_check_min_interval];
skvlada5d94ff2017-02-02 13:02:30 -0800118 }
Steve Anton8cb344a2018-02-27 15:34:53 -0800119 _sdpSemantics = [[self class] sdpSemanticsForNativeSdpSemantics:config.sdp_semantics];
Zeke Chinef1140e2017-10-27 15:42:08 -0700120 _turnCustomizer = config.turn_customizer;
Zhi Huangb57e1692018-06-12 11:41:11 -0700121 _activeResetSrtpParams = config.active_reset_srtp_params;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700122 if (config.crypto_options) {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +0200123 _cryptoOptions = [[RTC_OBJC_TYPE(RTCCryptoOptions) alloc]
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700124 initWithSrtpEnableGcmCryptoSuites:config.crypto_options->srtp
125 .enable_gcm_crypto_suites
126 srtpEnableAes128Sha1_32CryptoCipher:config.crypto_options->srtp
127 .enable_aes128_sha1_32_crypto_cipher
128 srtpEnableEncryptedRtpHeaderExtensions:config.crypto_options->srtp
129 .enable_encrypted_rtp_header_extensions
130 sframeRequireFrameEncryption:config.crypto_options->sframe
131 .require_frame_encryption];
132 }
Brad Pughf24143d2020-11-16 16:27:20 -0800133 _turnLoggingId = [NSString stringWithUTF8String:config.turn_logging_id.c_str()];
Jiawei Oub1e47752018-11-13 23:48:19 -0800134 _rtcpAudioReportIntervalMs = config.audio_rtcp_report_interval_ms();
135 _rtcpVideoReportIntervalMs = config.video_rtcp_report_interval_ms();
philipel3eb84f02019-11-11 12:57:44 +0100136 _allowCodecSwitching = config.allow_codec_switching.value_or(false);
hjon6d49a8e2016-01-26 13:06:42 -0800137 }
138 return self;
139}
140
141- (NSString *)description {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +0200142 static NSString *formatString = @"RTC_OBJC_TYPE(RTCConfiguration): "
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300143 @"{\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%d\n%d\n%d\n%d\n%d\n%d\n"
Niels Möller938bc332020-06-10 17:36:17 +0200144 @"%d\n%@\n%d\n%d\n%d\n%d\n%d\n%@\n}\n";
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100145
Steve Anton8cb344a2018-02-27 15:34:53 -0800146 return [NSString
147 stringWithFormat:formatString,
148 _iceServers,
149 [[self class] stringForTransportPolicy:_iceTransportPolicy],
150 [[self class] stringForBundlePolicy:_bundlePolicy],
151 [[self class] stringForRtcpMuxPolicy:_rtcpMuxPolicy],
152 [[self class] stringForTcpCandidatePolicy:_tcpCandidatePolicy],
153 [[self class] stringForCandidateNetworkPolicy:_candidateNetworkPolicy],
154 [[self class] stringForContinualGatheringPolicy:_continualGatheringPolicy],
155 [[self class] stringForSdpSemantics:_sdpSemantics],
156 _audioJitterBufferMaxPackets,
157 _audioJitterBufferFastAccelerate,
158 _iceConnectionReceivingTimeout,
159 _iceBackupCandidatePairPingInterval,
160 _iceCandidatePoolSize,
161 _shouldPruneTurnPorts,
162 _shouldPresumeWritableWhenFullyRelayed,
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700163 _shouldSurfaceIceCandidatesOnIceTransportTypeChanged,
Steve Anton8cb344a2018-02-27 15:34:53 -0800164 _iceCheckMinInterval,
Steve Anton8cb344a2018-02-27 15:34:53 -0800165 _disableLinkLocalNetworks,
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300166 _disableIPV6,
167 _disableIPV6OnWiFi,
Zhi Huangb57e1692018-06-12 11:41:11 -0700168 _maxIPv6Networks,
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -0700169 _activeResetSrtpParams,
Taylor Brandstetter21c80322020-03-24 15:41:19 -0700170 _enableDscp];
hjon6d49a8e2016-01-26 13:06:42 -0800171}
172
173#pragma mark - Private
174
hbosa73ca562016-05-17 03:28:58 -0700175- (webrtc::PeerConnectionInterface::RTCConfiguration *)
176 createNativeConfiguration {
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200177 std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration>
Honghai Zhangf7ddc062016-09-01 15:34:01 -0700178 nativeConfig(new webrtc::PeerConnectionInterface::RTCConfiguration(
179 webrtc::PeerConnectionInterface::RTCConfigurationType::kAggressive));
hjon6d49a8e2016-01-26 13:06:42 -0800180
Taylor Brandstetter21c80322020-03-24 15:41:19 -0700181 nativeConfig->set_dscp(_enableDscp);
Mirko Bonadeia81e9c82020-05-04 16:14:32 +0200182 for (RTC_OBJC_TYPE(RTCIceServer) * iceServer in _iceServers) {
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200183 nativeConfig->servers.push_back(iceServer.nativeServer);
hjon6d49a8e2016-01-26 13:06:42 -0800184 }
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200185 nativeConfig->type =
hjon6d49a8e2016-01-26 13:06:42 -0800186 [[self class] nativeTransportsTypeForTransportPolicy:_iceTransportPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200187 nativeConfig->bundle_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800188 [[self class] nativeBundlePolicyForPolicy:_bundlePolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200189 nativeConfig->rtcp_mux_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800190 [[self class] nativeRtcpMuxPolicyForPolicy:_rtcpMuxPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200191 nativeConfig->tcp_candidate_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800192 [[self class] nativeTcpCandidatePolicyForPolicy:_tcpCandidatePolicy];
Honghai Zhang46007ae2016-06-03 16:31:32 -0700193 nativeConfig->candidate_network_policy = [[self class]
194 nativeCandidateNetworkPolicyForPolicy:_candidateNetworkPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200195 nativeConfig->continual_gathering_policy = [[self class]
Honghai Zhang3108fc92016-05-11 10:10:39 -0700196 nativeContinualGatheringPolicyForPolicy:_continualGatheringPolicy];
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300197 nativeConfig->disable_ipv6 = _disableIPV6;
198 nativeConfig->disable_ipv6_on_wifi = _disableIPV6OnWiFi;
deadbeef2059bb32017-07-26 18:25:43 -0700199 nativeConfig->max_ipv6_networks = _maxIPv6Networks;
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100200 nativeConfig->disable_link_local_networks = _disableLinkLocalNetworks;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200201 nativeConfig->audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets;
hayscc9f95002016-12-05 14:24:32 -0800202 nativeConfig->audio_jitter_buffer_fast_accelerate =
203 _audioJitterBufferFastAccelerate ? true : false;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200204 nativeConfig->ice_connection_receiving_timeout =
hjon6d49a8e2016-01-26 13:06:42 -0800205 _iceConnectionReceivingTimeout;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200206 nativeConfig->ice_backup_candidate_pair_ping_interval =
hjon6d49a8e2016-01-26 13:06:42 -0800207 _iceBackupCandidatePairPingInterval;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200208 rtc::KeyType keyType =
209 [[self class] nativeEncryptionKeyTypeForKeyType:_keyType];
Michael Iedemaccee56b2018-07-05 15:28:24 +0200210 if (_certificate != nullptr) {
211 // if offered a pemcert use it...
212 RTC_LOG(LS_INFO) << "Have configured cert - using it.";
213 std::string pem_private_key = [[_certificate private_key] UTF8String];
214 std::string pem_certificate = [[_certificate certificate] UTF8String];
215 rtc::RTCCertificatePEM pem = rtc::RTCCertificatePEM(pem_private_key, pem_certificate);
216 rtc::scoped_refptr<rtc::RTCCertificate> certificate = rtc::RTCCertificate::FromPEM(pem);
217 RTC_LOG(LS_INFO) << "Created cert from PEM strings.";
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200218 if (!certificate) {
Michael Iedemaccee56b2018-07-05 15:28:24 +0200219 RTC_LOG(LS_ERROR) << "Failed to generate certificate from PEM.";
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200220 return nullptr;
tkchinab8f82f2016-01-27 17:50:11 -0800221 }
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200222 nativeConfig->certificates.push_back(certificate);
Michael Iedemaccee56b2018-07-05 15:28:24 +0200223 } else {
224 RTC_LOG(LS_INFO) << "Don't have configured cert.";
225 // Generate non-default certificate.
226 if (keyType != rtc::KT_DEFAULT) {
227 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
228 rtc::RTCCertificateGenerator::GenerateCertificate(rtc::KeyParams(keyType),
229 absl::optional<uint64_t>());
230 if (!certificate) {
231 RTCLogError(@"Failed to generate certificate.");
232 return nullptr;
233 }
234 nativeConfig->certificates.push_back(certificate);
235 }
tkchinab8f82f2016-01-27 17:50:11 -0800236 }
deadbeefbe0c96f2016-05-18 16:20:14 -0700237 nativeConfig->ice_candidate_pool_size = _iceCandidatePoolSize;
honghaizaf6b6e02016-07-11 15:09:26 -0700238 nativeConfig->prune_turn_ports = _shouldPruneTurnPorts ? true : false;
Taylor Brandstettere9851112016-07-01 11:11:13 -0700239 nativeConfig->presume_writable_when_fully_relayed =
honghaizaf6b6e02016-07-11 15:09:26 -0700240 _shouldPresumeWritableWhenFullyRelayed ? true : false;
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700241 nativeConfig->surface_ice_candidates_on_ice_transport_type_changed =
242 _shouldSurfaceIceCandidatesOnIceTransportTypeChanged ? true : false;
skvlada5d94ff2017-02-02 13:02:30 -0800243 if (_iceCheckMinInterval != nil) {
Danil Chapovalov196100e2018-06-21 10:17:24 +0200244 nativeConfig->ice_check_min_interval = absl::optional<int>(_iceCheckMinInterval.intValue);
skvlada5d94ff2017-02-02 13:02:30 -0800245 }
Steve Anton8cb344a2018-02-27 15:34:53 -0800246 nativeConfig->sdp_semantics = [[self class] nativeSdpSemanticsForSdpSemantics:_sdpSemantics];
Zeke Chinef1140e2017-10-27 15:42:08 -0700247 if (_turnCustomizer) {
248 nativeConfig->turn_customizer = _turnCustomizer;
249 }
Zhi Huangb57e1692018-06-12 11:41:11 -0700250 nativeConfig->active_reset_srtp_params = _activeResetSrtpParams ? true : false;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700251 if (_cryptoOptions) {
252 webrtc::CryptoOptions nativeCryptoOptions;
253 nativeCryptoOptions.srtp.enable_gcm_crypto_suites =
254 _cryptoOptions.srtpEnableGcmCryptoSuites ? true : false;
255 nativeCryptoOptions.srtp.enable_aes128_sha1_32_crypto_cipher =
256 _cryptoOptions.srtpEnableAes128Sha1_32CryptoCipher ? true : false;
257 nativeCryptoOptions.srtp.enable_encrypted_rtp_header_extensions =
258 _cryptoOptions.srtpEnableEncryptedRtpHeaderExtensions ? true : false;
259 nativeCryptoOptions.sframe.require_frame_encryption =
260 _cryptoOptions.sframeRequireFrameEncryption ? true : false;
261 nativeConfig->crypto_options = absl::optional<webrtc::CryptoOptions>(nativeCryptoOptions);
262 }
Brad Pughf24143d2020-11-16 16:27:20 -0800263 nativeConfig->turn_logging_id = [_turnLoggingId UTF8String];
Jiawei Oub1e47752018-11-13 23:48:19 -0800264 nativeConfig->set_audio_rtcp_report_interval_ms(_rtcpAudioReportIntervalMs);
265 nativeConfig->set_video_rtcp_report_interval_ms(_rtcpVideoReportIntervalMs);
philipel3eb84f02019-11-11 12:57:44 +0100266 nativeConfig->allow_codec_switching = _allowCodecSwitching;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200267 return nativeConfig.release();
hjon6d49a8e2016-01-26 13:06:42 -0800268}
269
hjon6d49a8e2016-01-26 13:06:42 -0800270+ (webrtc::PeerConnectionInterface::IceTransportsType)
271 nativeTransportsTypeForTransportPolicy:(RTCIceTransportPolicy)policy {
272 switch (policy) {
273 case RTCIceTransportPolicyNone:
274 return webrtc::PeerConnectionInterface::kNone;
275 case RTCIceTransportPolicyRelay:
276 return webrtc::PeerConnectionInterface::kRelay;
277 case RTCIceTransportPolicyNoHost:
278 return webrtc::PeerConnectionInterface::kNoHost;
279 case RTCIceTransportPolicyAll:
280 return webrtc::PeerConnectionInterface::kAll;
281 }
282}
283
284+ (RTCIceTransportPolicy)transportPolicyForTransportsType:
285 (webrtc::PeerConnectionInterface::IceTransportsType)nativeType {
286 switch (nativeType) {
287 case webrtc::PeerConnectionInterface::kNone:
288 return RTCIceTransportPolicyNone;
289 case webrtc::PeerConnectionInterface::kRelay:
290 return RTCIceTransportPolicyRelay;
291 case webrtc::PeerConnectionInterface::kNoHost:
292 return RTCIceTransportPolicyNoHost;
293 case webrtc::PeerConnectionInterface::kAll:
294 return RTCIceTransportPolicyAll;
295 }
296}
297
298+ (NSString *)stringForTransportPolicy:(RTCIceTransportPolicy)policy {
299 switch (policy) {
300 case RTCIceTransportPolicyNone:
301 return @"NONE";
302 case RTCIceTransportPolicyRelay:
303 return @"RELAY";
304 case RTCIceTransportPolicyNoHost:
305 return @"NO_HOST";
306 case RTCIceTransportPolicyAll:
307 return @"ALL";
308 }
309}
310
311+ (webrtc::PeerConnectionInterface::BundlePolicy)nativeBundlePolicyForPolicy:
312 (RTCBundlePolicy)policy {
313 switch (policy) {
314 case RTCBundlePolicyBalanced:
315 return webrtc::PeerConnectionInterface::kBundlePolicyBalanced;
316 case RTCBundlePolicyMaxCompat:
317 return webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat;
318 case RTCBundlePolicyMaxBundle:
319 return webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle;
320 }
321}
322
323+ (RTCBundlePolicy)bundlePolicyForNativePolicy:
324 (webrtc::PeerConnectionInterface::BundlePolicy)nativePolicy {
325 switch (nativePolicy) {
326 case webrtc::PeerConnectionInterface::kBundlePolicyBalanced:
327 return RTCBundlePolicyBalanced;
328 case webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat:
329 return RTCBundlePolicyMaxCompat;
330 case webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle:
331 return RTCBundlePolicyMaxBundle;
332 }
333}
334
335+ (NSString *)stringForBundlePolicy:(RTCBundlePolicy)policy {
336 switch (policy) {
337 case RTCBundlePolicyBalanced:
338 return @"BALANCED";
339 case RTCBundlePolicyMaxCompat:
340 return @"MAX_COMPAT";
341 case RTCBundlePolicyMaxBundle:
342 return @"MAX_BUNDLE";
343 }
344}
345
346+ (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativeRtcpMuxPolicyForPolicy:
347 (RTCRtcpMuxPolicy)policy {
348 switch (policy) {
349 case RTCRtcpMuxPolicyNegotiate:
350 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
351 case RTCRtcpMuxPolicyRequire:
352 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire;
353 }
354}
355
356+ (RTCRtcpMuxPolicy)rtcpMuxPolicyForNativePolicy:
357 (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativePolicy {
358 switch (nativePolicy) {
359 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate:
360 return RTCRtcpMuxPolicyNegotiate;
361 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire:
362 return RTCRtcpMuxPolicyRequire;
363 }
364}
365
366+ (NSString *)stringForRtcpMuxPolicy:(RTCRtcpMuxPolicy)policy {
367 switch (policy) {
368 case RTCRtcpMuxPolicyNegotiate:
369 return @"NEGOTIATE";
370 case RTCRtcpMuxPolicyRequire:
371 return @"REQUIRE";
372 }
373}
374
375+ (webrtc::PeerConnectionInterface::TcpCandidatePolicy)
376 nativeTcpCandidatePolicyForPolicy:(RTCTcpCandidatePolicy)policy {
377 switch (policy) {
378 case RTCTcpCandidatePolicyEnabled:
379 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled;
380 case RTCTcpCandidatePolicyDisabled:
381 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled;
382 }
383}
384
Honghai Zhang46007ae2016-06-03 16:31:32 -0700385+ (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)
386 nativeCandidateNetworkPolicyForPolicy:(RTCCandidateNetworkPolicy)policy {
387 switch (policy) {
388 case RTCCandidateNetworkPolicyAll:
389 return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll;
390 case RTCCandidateNetworkPolicyLowCost:
391 return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
392 }
393}
394
hjon6d49a8e2016-01-26 13:06:42 -0800395+ (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativePolicy:
396 (webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativePolicy {
397 switch (nativePolicy) {
398 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled:
399 return RTCTcpCandidatePolicyEnabled;
400 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled:
401 return RTCTcpCandidatePolicyDisabled;
402 }
403}
404
405+ (NSString *)stringForTcpCandidatePolicy:(RTCTcpCandidatePolicy)policy {
406 switch (policy) {
407 case RTCTcpCandidatePolicyEnabled:
408 return @"TCP_ENABLED";
409 case RTCTcpCandidatePolicyDisabled:
410 return @"TCP_DISABLED";
411 }
412}
413
Honghai Zhang46007ae2016-06-03 16:31:32 -0700414+ (RTCCandidateNetworkPolicy)candidateNetworkPolicyForNativePolicy:
415 (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)nativePolicy {
416 switch (nativePolicy) {
417 case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll:
418 return RTCCandidateNetworkPolicyAll;
419 case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost:
420 return RTCCandidateNetworkPolicyLowCost;
421 }
422}
423
424+ (NSString *)stringForCandidateNetworkPolicy:
425 (RTCCandidateNetworkPolicy)policy {
426 switch (policy) {
427 case RTCCandidateNetworkPolicyAll:
428 return @"CANDIDATE_ALL_NETWORKS";
429 case RTCCandidateNetworkPolicyLowCost:
430 return @"CANDIDATE_LOW_COST_NETWORKS";
431 }
432}
433
Honghai Zhang3108fc92016-05-11 10:10:39 -0700434+ (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)
435 nativeContinualGatheringPolicyForPolicy:
436 (RTCContinualGatheringPolicy)policy {
437 switch (policy) {
438 case RTCContinualGatheringPolicyGatherOnce:
439 return webrtc::PeerConnectionInterface::GATHER_ONCE;
440 case RTCContinualGatheringPolicyGatherContinually:
441 return webrtc::PeerConnectionInterface::GATHER_CONTINUALLY;
442 }
443}
444
445+ (RTCContinualGatheringPolicy)continualGatheringPolicyForNativePolicy:
446 (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)nativePolicy {
447 switch (nativePolicy) {
448 case webrtc::PeerConnectionInterface::GATHER_ONCE:
449 return RTCContinualGatheringPolicyGatherOnce;
450 case webrtc::PeerConnectionInterface::GATHER_CONTINUALLY:
451 return RTCContinualGatheringPolicyGatherContinually;
452 }
453}
454
455+ (NSString *)stringForContinualGatheringPolicy:
456 (RTCContinualGatheringPolicy)policy {
457 switch (policy) {
458 case RTCContinualGatheringPolicyGatherOnce:
459 return @"GATHER_ONCE";
460 case RTCContinualGatheringPolicyGatherContinually:
461 return @"GATHER_CONTINUALLY";
462 }
463}
464
hbosf9da44d2016-06-09 03:18:28 -0700465+ (rtc::KeyType)nativeEncryptionKeyTypeForKeyType:
466 (RTCEncryptionKeyType)keyType {
467 switch (keyType) {
468 case RTCEncryptionKeyTypeRSA:
469 return rtc::KT_RSA;
470 case RTCEncryptionKeyTypeECDSA:
471 return rtc::KT_ECDSA;
472 }
473}
474
Steve Anton8cb344a2018-02-27 15:34:53 -0800475+ (webrtc::SdpSemantics)nativeSdpSemanticsForSdpSemantics:(RTCSdpSemantics)sdpSemantics {
476 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800477 case RTCSdpSemanticsPlanB:
478 return webrtc::SdpSemantics::kPlanB;
479 case RTCSdpSemanticsUnifiedPlan:
480 return webrtc::SdpSemantics::kUnifiedPlan;
481 }
482}
483
484+ (RTCSdpSemantics)sdpSemanticsForNativeSdpSemantics:(webrtc::SdpSemantics)sdpSemantics {
485 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800486 case webrtc::SdpSemantics::kPlanB:
487 return RTCSdpSemanticsPlanB;
488 case webrtc::SdpSemantics::kUnifiedPlan:
489 return RTCSdpSemanticsUnifiedPlan;
490 }
491}
492
493+ (NSString *)stringForSdpSemantics:(RTCSdpSemantics)sdpSemantics {
494 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800495 case RTCSdpSemanticsPlanB:
496 return @"PLAN_B";
497 case RTCSdpSemanticsUnifiedPlan:
498 return @"UNIFIED_PLAN";
499 }
500}
501
hjon6d49a8e2016-01-26 13:06:42 -0800502@end