blob: 7503a0a01f2d46f0f7e3ae0d0acbd281512fd715 [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"
Steve Antond295e402017-07-14 16:06:41 -070018#import "RTCIntervalRange+Private.h"
Anders Carlsson7bca8ca2018-08-30 09:30:29 +020019#import "base/RTCLogging.h"
tkchinab8f82f2016-01-27 17:50:11 -080020
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
24@implementation RTCConfiguration
25
26@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 Antond295e402017-07-14 16:06:41 -070051@synthesize iceRegatherIntervalRange = _iceRegatherIntervalRange;
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;
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -070056@synthesize useMediaTransport = _useMediaTransport;
Bjorn Mellema9bbd862018-11-02 09:07:48 -070057@synthesize useMediaTransportForDataChannels = _useMediaTransportForDataChannels;
Benjamin Wright8c27cca2018-10-25 10:16:44 -070058@synthesize cryptoOptions = _cryptoOptions;
Jiawei Oub1e47752018-11-13 23:48:19 -080059@synthesize rtcpAudioReportIntervalMs = _rtcpAudioReportIntervalMs;
60@synthesize rtcpVideoReportIntervalMs = _rtcpVideoReportIntervalMs;
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]) {
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) {
jtteh4eeb5372017-04-03 15:06:37 -070073 RTCIceServer *iceServer = [[RTCIceServer alloc] initWithNativeServer:server];
74 [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();
81 _certificate =
82 [[RTCCertificate alloc] initWithPrivateKey:@(native_pem.private_key().c_str())
83 certificate:@(native_pem.certificate().c_str())];
84 }
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;
Piotr (Peter) Slatala693432d2018-10-30 16:52:06 -0700108 _useMediaTransport = config.use_media_transport;
Bjorn Mellema9bbd862018-11-02 09:07:48 -0700109 _useMediaTransportForDataChannels = config.use_media_transport_for_data_channels;
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 Antond295e402017-07-14 16:06:41 -0700121 if (config.ice_regather_interval_range) {
122 const rtc::IntervalRange &nativeIntervalRange = config.ice_regather_interval_range.value();
123 _iceRegatherIntervalRange =
124 [[RTCIntervalRange alloc] initWithNativeIntervalRange:nativeIntervalRange];
125 }
Steve Anton8cb344a2018-02-27 15:34:53 -0800126 _sdpSemantics = [[self class] sdpSemanticsForNativeSdpSemantics:config.sdp_semantics];
Zeke Chinef1140e2017-10-27 15:42:08 -0700127 _turnCustomizer = config.turn_customizer;
Zhi Huangb57e1692018-06-12 11:41:11 -0700128 _activeResetSrtpParams = config.active_reset_srtp_params;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700129 if (config.crypto_options) {
130 _cryptoOptions = [[RTCCryptoOptions alloc]
131 initWithSrtpEnableGcmCryptoSuites:config.crypto_options->srtp
132 .enable_gcm_crypto_suites
133 srtpEnableAes128Sha1_32CryptoCipher:config.crypto_options->srtp
134 .enable_aes128_sha1_32_crypto_cipher
135 srtpEnableEncryptedRtpHeaderExtensions:config.crypto_options->srtp
136 .enable_encrypted_rtp_header_extensions
137 sframeRequireFrameEncryption:config.crypto_options->sframe
138 .require_frame_encryption];
139 }
Jiawei Oub1e47752018-11-13 23:48:19 -0800140 _rtcpAudioReportIntervalMs = config.audio_rtcp_report_interval_ms();
141 _rtcpVideoReportIntervalMs = config.video_rtcp_report_interval_ms();
philipel3eb84f02019-11-11 12:57:44 +0100142 _allowCodecSwitching = config.allow_codec_switching.value_or(false);
hjon6d49a8e2016-01-26 13:06:42 -0800143 }
144 return self;
145}
146
147- (NSString *)description {
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300148 static NSString *formatString = @"RTCConfiguration: "
149 @"{\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%d\n%d\n%d\n%d\n%d\n%d\n"
150 @"%d\n%@\n%@\n%d\n%d\n%d\n%d\n%d\n%@\n}\n";
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100151
Steve Anton8cb344a2018-02-27 15:34:53 -0800152 return [NSString
153 stringWithFormat:formatString,
154 _iceServers,
155 [[self class] stringForTransportPolicy:_iceTransportPolicy],
156 [[self class] stringForBundlePolicy:_bundlePolicy],
157 [[self class] stringForRtcpMuxPolicy:_rtcpMuxPolicy],
158 [[self class] stringForTcpCandidatePolicy:_tcpCandidatePolicy],
159 [[self class] stringForCandidateNetworkPolicy:_candidateNetworkPolicy],
160 [[self class] stringForContinualGatheringPolicy:_continualGatheringPolicy],
161 [[self class] stringForSdpSemantics:_sdpSemantics],
162 _audioJitterBufferMaxPackets,
163 _audioJitterBufferFastAccelerate,
164 _iceConnectionReceivingTimeout,
165 _iceBackupCandidatePairPingInterval,
166 _iceCandidatePoolSize,
167 _shouldPruneTurnPorts,
168 _shouldPresumeWritableWhenFullyRelayed,
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700169 _shouldSurfaceIceCandidatesOnIceTransportTypeChanged,
Steve Anton8cb344a2018-02-27 15:34:53 -0800170 _iceCheckMinInterval,
171 _iceRegatherIntervalRange,
172 _disableLinkLocalNetworks,
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300173 _disableIPV6,
174 _disableIPV6OnWiFi,
Zhi Huangb57e1692018-06-12 11:41:11 -0700175 _maxIPv6Networks,
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -0700176 _activeResetSrtpParams,
177 _useMediaTransport];
hjon6d49a8e2016-01-26 13:06:42 -0800178}
179
180#pragma mark - Private
181
hbosa73ca562016-05-17 03:28:58 -0700182- (webrtc::PeerConnectionInterface::RTCConfiguration *)
183 createNativeConfiguration {
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200184 std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration>
Honghai Zhangf7ddc062016-09-01 15:34:01 -0700185 nativeConfig(new webrtc::PeerConnectionInterface::RTCConfiguration(
186 webrtc::PeerConnectionInterface::RTCConfigurationType::kAggressive));
hjon6d49a8e2016-01-26 13:06:42 -0800187
188 for (RTCIceServer *iceServer in _iceServers) {
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200189 nativeConfig->servers.push_back(iceServer.nativeServer);
hjon6d49a8e2016-01-26 13:06:42 -0800190 }
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200191 nativeConfig->type =
hjon6d49a8e2016-01-26 13:06:42 -0800192 [[self class] nativeTransportsTypeForTransportPolicy:_iceTransportPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200193 nativeConfig->bundle_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800194 [[self class] nativeBundlePolicyForPolicy:_bundlePolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200195 nativeConfig->rtcp_mux_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800196 [[self class] nativeRtcpMuxPolicyForPolicy:_rtcpMuxPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200197 nativeConfig->tcp_candidate_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800198 [[self class] nativeTcpCandidatePolicyForPolicy:_tcpCandidatePolicy];
Honghai Zhang46007ae2016-06-03 16:31:32 -0700199 nativeConfig->candidate_network_policy = [[self class]
200 nativeCandidateNetworkPolicyForPolicy:_candidateNetworkPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200201 nativeConfig->continual_gathering_policy = [[self class]
Honghai Zhang3108fc92016-05-11 10:10:39 -0700202 nativeContinualGatheringPolicyForPolicy:_continualGatheringPolicy];
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300203 nativeConfig->disable_ipv6 = _disableIPV6;
204 nativeConfig->disable_ipv6_on_wifi = _disableIPV6OnWiFi;
deadbeef2059bb32017-07-26 18:25:43 -0700205 nativeConfig->max_ipv6_networks = _maxIPv6Networks;
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100206 nativeConfig->disable_link_local_networks = _disableLinkLocalNetworks;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200207 nativeConfig->audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets;
hayscc9f95002016-12-05 14:24:32 -0800208 nativeConfig->audio_jitter_buffer_fast_accelerate =
209 _audioJitterBufferFastAccelerate ? true : false;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200210 nativeConfig->ice_connection_receiving_timeout =
hjon6d49a8e2016-01-26 13:06:42 -0800211 _iceConnectionReceivingTimeout;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200212 nativeConfig->ice_backup_candidate_pair_ping_interval =
hjon6d49a8e2016-01-26 13:06:42 -0800213 _iceBackupCandidatePairPingInterval;
Piotr (Peter) Slatala88d8d7d2018-10-26 15:06:17 -0700214 nativeConfig->use_media_transport = _useMediaTransport;
Bjorn Mellema9bbd862018-11-02 09:07:48 -0700215 nativeConfig->use_media_transport_for_data_channels = _useMediaTransportForDataChannels;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200216 rtc::KeyType keyType =
217 [[self class] nativeEncryptionKeyTypeForKeyType:_keyType];
Michael Iedemaccee56b2018-07-05 15:28:24 +0200218 if (_certificate != nullptr) {
219 // if offered a pemcert use it...
220 RTC_LOG(LS_INFO) << "Have configured cert - using it.";
221 std::string pem_private_key = [[_certificate private_key] UTF8String];
222 std::string pem_certificate = [[_certificate certificate] UTF8String];
223 rtc::RTCCertificatePEM pem = rtc::RTCCertificatePEM(pem_private_key, pem_certificate);
224 rtc::scoped_refptr<rtc::RTCCertificate> certificate = rtc::RTCCertificate::FromPEM(pem);
225 RTC_LOG(LS_INFO) << "Created cert from PEM strings.";
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200226 if (!certificate) {
Michael Iedemaccee56b2018-07-05 15:28:24 +0200227 RTC_LOG(LS_ERROR) << "Failed to generate certificate from PEM.";
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200228 return nullptr;
tkchinab8f82f2016-01-27 17:50:11 -0800229 }
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200230 nativeConfig->certificates.push_back(certificate);
Michael Iedemaccee56b2018-07-05 15:28:24 +0200231 } else {
232 RTC_LOG(LS_INFO) << "Don't have configured cert.";
233 // Generate non-default certificate.
234 if (keyType != rtc::KT_DEFAULT) {
235 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
236 rtc::RTCCertificateGenerator::GenerateCertificate(rtc::KeyParams(keyType),
237 absl::optional<uint64_t>());
238 if (!certificate) {
239 RTCLogError(@"Failed to generate certificate.");
240 return nullptr;
241 }
242 nativeConfig->certificates.push_back(certificate);
243 }
tkchinab8f82f2016-01-27 17:50:11 -0800244 }
deadbeefbe0c96f2016-05-18 16:20:14 -0700245 nativeConfig->ice_candidate_pool_size = _iceCandidatePoolSize;
honghaizaf6b6e02016-07-11 15:09:26 -0700246 nativeConfig->prune_turn_ports = _shouldPruneTurnPorts ? true : false;
Taylor Brandstettere9851112016-07-01 11:11:13 -0700247 nativeConfig->presume_writable_when_fully_relayed =
honghaizaf6b6e02016-07-11 15:09:26 -0700248 _shouldPresumeWritableWhenFullyRelayed ? true : false;
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700249 nativeConfig->surface_ice_candidates_on_ice_transport_type_changed =
250 _shouldSurfaceIceCandidatesOnIceTransportTypeChanged ? true : false;
skvlada5d94ff2017-02-02 13:02:30 -0800251 if (_iceCheckMinInterval != nil) {
Danil Chapovalov196100e2018-06-21 10:17:24 +0200252 nativeConfig->ice_check_min_interval = absl::optional<int>(_iceCheckMinInterval.intValue);
skvlada5d94ff2017-02-02 13:02:30 -0800253 }
Steve Antond295e402017-07-14 16:06:41 -0700254 if (_iceRegatherIntervalRange != nil) {
255 std::unique_ptr<rtc::IntervalRange> nativeIntervalRange(
256 _iceRegatherIntervalRange.nativeIntervalRange);
257 nativeConfig->ice_regather_interval_range =
Danil Chapovalov196100e2018-06-21 10:17:24 +0200258 absl::optional<rtc::IntervalRange>(*nativeIntervalRange);
Steve Antond295e402017-07-14 16:06:41 -0700259 }
Steve Anton8cb344a2018-02-27 15:34:53 -0800260 nativeConfig->sdp_semantics = [[self class] nativeSdpSemanticsForSdpSemantics:_sdpSemantics];
Zeke Chinef1140e2017-10-27 15:42:08 -0700261 if (_turnCustomizer) {
262 nativeConfig->turn_customizer = _turnCustomizer;
263 }
Zhi Huangb57e1692018-06-12 11:41:11 -0700264 nativeConfig->active_reset_srtp_params = _activeResetSrtpParams ? true : false;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700265 if (_cryptoOptions) {
266 webrtc::CryptoOptions nativeCryptoOptions;
267 nativeCryptoOptions.srtp.enable_gcm_crypto_suites =
268 _cryptoOptions.srtpEnableGcmCryptoSuites ? true : false;
269 nativeCryptoOptions.srtp.enable_aes128_sha1_32_crypto_cipher =
270 _cryptoOptions.srtpEnableAes128Sha1_32CryptoCipher ? true : false;
271 nativeCryptoOptions.srtp.enable_encrypted_rtp_header_extensions =
272 _cryptoOptions.srtpEnableEncryptedRtpHeaderExtensions ? true : false;
273 nativeCryptoOptions.sframe.require_frame_encryption =
274 _cryptoOptions.sframeRequireFrameEncryption ? true : false;
275 nativeConfig->crypto_options = absl::optional<webrtc::CryptoOptions>(nativeCryptoOptions);
276 }
Jiawei Oub1e47752018-11-13 23:48:19 -0800277 nativeConfig->set_audio_rtcp_report_interval_ms(_rtcpAudioReportIntervalMs);
278 nativeConfig->set_video_rtcp_report_interval_ms(_rtcpVideoReportIntervalMs);
philipel3eb84f02019-11-11 12:57:44 +0100279 nativeConfig->allow_codec_switching = _allowCodecSwitching;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200280 return nativeConfig.release();
hjon6d49a8e2016-01-26 13:06:42 -0800281}
282
hjon6d49a8e2016-01-26 13:06:42 -0800283+ (webrtc::PeerConnectionInterface::IceTransportsType)
284 nativeTransportsTypeForTransportPolicy:(RTCIceTransportPolicy)policy {
285 switch (policy) {
286 case RTCIceTransportPolicyNone:
287 return webrtc::PeerConnectionInterface::kNone;
288 case RTCIceTransportPolicyRelay:
289 return webrtc::PeerConnectionInterface::kRelay;
290 case RTCIceTransportPolicyNoHost:
291 return webrtc::PeerConnectionInterface::kNoHost;
292 case RTCIceTransportPolicyAll:
293 return webrtc::PeerConnectionInterface::kAll;
294 }
295}
296
297+ (RTCIceTransportPolicy)transportPolicyForTransportsType:
298 (webrtc::PeerConnectionInterface::IceTransportsType)nativeType {
299 switch (nativeType) {
300 case webrtc::PeerConnectionInterface::kNone:
301 return RTCIceTransportPolicyNone;
302 case webrtc::PeerConnectionInterface::kRelay:
303 return RTCIceTransportPolicyRelay;
304 case webrtc::PeerConnectionInterface::kNoHost:
305 return RTCIceTransportPolicyNoHost;
306 case webrtc::PeerConnectionInterface::kAll:
307 return RTCIceTransportPolicyAll;
308 }
309}
310
311+ (NSString *)stringForTransportPolicy:(RTCIceTransportPolicy)policy {
312 switch (policy) {
313 case RTCIceTransportPolicyNone:
314 return @"NONE";
315 case RTCIceTransportPolicyRelay:
316 return @"RELAY";
317 case RTCIceTransportPolicyNoHost:
318 return @"NO_HOST";
319 case RTCIceTransportPolicyAll:
320 return @"ALL";
321 }
322}
323
324+ (webrtc::PeerConnectionInterface::BundlePolicy)nativeBundlePolicyForPolicy:
325 (RTCBundlePolicy)policy {
326 switch (policy) {
327 case RTCBundlePolicyBalanced:
328 return webrtc::PeerConnectionInterface::kBundlePolicyBalanced;
329 case RTCBundlePolicyMaxCompat:
330 return webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat;
331 case RTCBundlePolicyMaxBundle:
332 return webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle;
333 }
334}
335
336+ (RTCBundlePolicy)bundlePolicyForNativePolicy:
337 (webrtc::PeerConnectionInterface::BundlePolicy)nativePolicy {
338 switch (nativePolicy) {
339 case webrtc::PeerConnectionInterface::kBundlePolicyBalanced:
340 return RTCBundlePolicyBalanced;
341 case webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat:
342 return RTCBundlePolicyMaxCompat;
343 case webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle:
344 return RTCBundlePolicyMaxBundle;
345 }
346}
347
348+ (NSString *)stringForBundlePolicy:(RTCBundlePolicy)policy {
349 switch (policy) {
350 case RTCBundlePolicyBalanced:
351 return @"BALANCED";
352 case RTCBundlePolicyMaxCompat:
353 return @"MAX_COMPAT";
354 case RTCBundlePolicyMaxBundle:
355 return @"MAX_BUNDLE";
356 }
357}
358
359+ (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativeRtcpMuxPolicyForPolicy:
360 (RTCRtcpMuxPolicy)policy {
361 switch (policy) {
362 case RTCRtcpMuxPolicyNegotiate:
363 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
364 case RTCRtcpMuxPolicyRequire:
365 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire;
366 }
367}
368
369+ (RTCRtcpMuxPolicy)rtcpMuxPolicyForNativePolicy:
370 (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativePolicy {
371 switch (nativePolicy) {
372 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate:
373 return RTCRtcpMuxPolicyNegotiate;
374 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire:
375 return RTCRtcpMuxPolicyRequire;
376 }
377}
378
379+ (NSString *)stringForRtcpMuxPolicy:(RTCRtcpMuxPolicy)policy {
380 switch (policy) {
381 case RTCRtcpMuxPolicyNegotiate:
382 return @"NEGOTIATE";
383 case RTCRtcpMuxPolicyRequire:
384 return @"REQUIRE";
385 }
386}
387
388+ (webrtc::PeerConnectionInterface::TcpCandidatePolicy)
389 nativeTcpCandidatePolicyForPolicy:(RTCTcpCandidatePolicy)policy {
390 switch (policy) {
391 case RTCTcpCandidatePolicyEnabled:
392 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled;
393 case RTCTcpCandidatePolicyDisabled:
394 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled;
395 }
396}
397
Honghai Zhang46007ae2016-06-03 16:31:32 -0700398+ (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)
399 nativeCandidateNetworkPolicyForPolicy:(RTCCandidateNetworkPolicy)policy {
400 switch (policy) {
401 case RTCCandidateNetworkPolicyAll:
402 return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll;
403 case RTCCandidateNetworkPolicyLowCost:
404 return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
405 }
406}
407
hjon6d49a8e2016-01-26 13:06:42 -0800408+ (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativePolicy:
409 (webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativePolicy {
410 switch (nativePolicy) {
411 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled:
412 return RTCTcpCandidatePolicyEnabled;
413 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled:
414 return RTCTcpCandidatePolicyDisabled;
415 }
416}
417
418+ (NSString *)stringForTcpCandidatePolicy:(RTCTcpCandidatePolicy)policy {
419 switch (policy) {
420 case RTCTcpCandidatePolicyEnabled:
421 return @"TCP_ENABLED";
422 case RTCTcpCandidatePolicyDisabled:
423 return @"TCP_DISABLED";
424 }
425}
426
Honghai Zhang46007ae2016-06-03 16:31:32 -0700427+ (RTCCandidateNetworkPolicy)candidateNetworkPolicyForNativePolicy:
428 (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)nativePolicy {
429 switch (nativePolicy) {
430 case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll:
431 return RTCCandidateNetworkPolicyAll;
432 case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost:
433 return RTCCandidateNetworkPolicyLowCost;
434 }
435}
436
437+ (NSString *)stringForCandidateNetworkPolicy:
438 (RTCCandidateNetworkPolicy)policy {
439 switch (policy) {
440 case RTCCandidateNetworkPolicyAll:
441 return @"CANDIDATE_ALL_NETWORKS";
442 case RTCCandidateNetworkPolicyLowCost:
443 return @"CANDIDATE_LOW_COST_NETWORKS";
444 }
445}
446
Honghai Zhang3108fc92016-05-11 10:10:39 -0700447+ (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)
448 nativeContinualGatheringPolicyForPolicy:
449 (RTCContinualGatheringPolicy)policy {
450 switch (policy) {
451 case RTCContinualGatheringPolicyGatherOnce:
452 return webrtc::PeerConnectionInterface::GATHER_ONCE;
453 case RTCContinualGatheringPolicyGatherContinually:
454 return webrtc::PeerConnectionInterface::GATHER_CONTINUALLY;
455 }
456}
457
458+ (RTCContinualGatheringPolicy)continualGatheringPolicyForNativePolicy:
459 (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)nativePolicy {
460 switch (nativePolicy) {
461 case webrtc::PeerConnectionInterface::GATHER_ONCE:
462 return RTCContinualGatheringPolicyGatherOnce;
463 case webrtc::PeerConnectionInterface::GATHER_CONTINUALLY:
464 return RTCContinualGatheringPolicyGatherContinually;
465 }
466}
467
468+ (NSString *)stringForContinualGatheringPolicy:
469 (RTCContinualGatheringPolicy)policy {
470 switch (policy) {
471 case RTCContinualGatheringPolicyGatherOnce:
472 return @"GATHER_ONCE";
473 case RTCContinualGatheringPolicyGatherContinually:
474 return @"GATHER_CONTINUALLY";
475 }
476}
477
hbosf9da44d2016-06-09 03:18:28 -0700478+ (rtc::KeyType)nativeEncryptionKeyTypeForKeyType:
479 (RTCEncryptionKeyType)keyType {
480 switch (keyType) {
481 case RTCEncryptionKeyTypeRSA:
482 return rtc::KT_RSA;
483 case RTCEncryptionKeyTypeECDSA:
484 return rtc::KT_ECDSA;
485 }
486}
487
Steve Anton8cb344a2018-02-27 15:34:53 -0800488+ (webrtc::SdpSemantics)nativeSdpSemanticsForSdpSemantics:(RTCSdpSemantics)sdpSemantics {
489 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800490 case RTCSdpSemanticsPlanB:
491 return webrtc::SdpSemantics::kPlanB;
492 case RTCSdpSemanticsUnifiedPlan:
493 return webrtc::SdpSemantics::kUnifiedPlan;
494 }
495}
496
497+ (RTCSdpSemantics)sdpSemanticsForNativeSdpSemantics:(webrtc::SdpSemantics)sdpSemantics {
498 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800499 case webrtc::SdpSemantics::kPlanB:
500 return RTCSdpSemanticsPlanB;
501 case webrtc::SdpSemantics::kUnifiedPlan:
502 return RTCSdpSemanticsUnifiedPlan;
503 }
504}
505
506+ (NSString *)stringForSdpSemantics:(RTCSdpSemantics)sdpSemantics {
507 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800508 case RTCSdpSemanticsPlanB:
509 return @"PLAN_B";
510 case RTCSdpSemanticsUnifiedPlan:
511 return @"UNIFIED_PLAN";
512 }
513}
514
hjon6d49a8e2016-01-26 13:06:42 -0800515@end