blob: 55abbcdb1842362a952ed5b9335a5140fda89454 [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;
Jiawei Oub1e47752018-11-13 23:48:19 -080056@synthesize rtcpAudioReportIntervalMs = _rtcpAudioReportIntervalMs;
57@synthesize rtcpVideoReportIntervalMs = _rtcpVideoReportIntervalMs;
hjon6d49a8e2016-01-26 13:06:42 -080058
59- (instancetype)init {
jtteh4eeb5372017-04-03 15:06:37 -070060 // Copy defaults.
Yuriy Pavlyshak8cec4fb2018-09-07 16:43:31 +020061 webrtc::PeerConnectionInterface::RTCConfiguration config;
jtteh465faf02017-04-04 14:00:16 -070062 return [self initWithNativeConfiguration:config];
jtteh4eeb5372017-04-03 15:06:37 -070063}
64
65- (instancetype)initWithNativeConfiguration:
jtteh465faf02017-04-04 14:00:16 -070066 (const webrtc::PeerConnectionInterface::RTCConfiguration &)config {
hjon6d49a8e2016-01-26 13:06:42 -080067 if (self = [super init]) {
Taylor Brandstetter21c80322020-03-24 15:41:19 -070068 _enableDscp = config.dscp();
jtteh4eeb5372017-04-03 15:06:37 -070069 NSMutableArray *iceServers = [NSMutableArray array];
jtteh465faf02017-04-04 14:00:16 -070070 for (const webrtc::PeerConnectionInterface::IceServer& server : config.servers) {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020071 RTC_OBJC_TYPE(RTCIceServer) *iceServer =
72 [[RTC_OBJC_TYPE(RTCIceServer) alloc] initWithNativeServer:server];
jtteh4eeb5372017-04-03 15:06:37 -070073 [iceServers addObject:iceServer];
74 }
75 _iceServers = iceServers;
Michael Iedemaccee56b2018-07-05 15:28:24 +020076 if (!config.certificates.empty()) {
77 rtc::scoped_refptr<rtc::RTCCertificate> native_cert;
78 native_cert = config.certificates[0];
79 rtc::RTCCertificatePEM native_pem = native_cert->ToPEM();
Mirko Bonadeia81e9c82020-05-04 16:14:32 +020080 _certificate = [[RTC_OBJC_TYPE(RTCCertificate) alloc]
81 initWithPrivateKey:@(native_pem.private_key().c_str())
82 certificate:@(native_pem.certificate().c_str())];
Michael Iedemaccee56b2018-07-05 15:28:24 +020083 }
hjon6d49a8e2016-01-26 13:06:42 -080084 _iceTransportPolicy =
jtteh465faf02017-04-04 14:00:16 -070085 [[self class] transportPolicyForTransportsType:config.type];
hjon6d49a8e2016-01-26 13:06:42 -080086 _bundlePolicy =
jtteh465faf02017-04-04 14:00:16 -070087 [[self class] bundlePolicyForNativePolicy:config.bundle_policy];
hjon6d49a8e2016-01-26 13:06:42 -080088 _rtcpMuxPolicy =
jtteh465faf02017-04-04 14:00:16 -070089 [[self class] rtcpMuxPolicyForNativePolicy:config.rtcp_mux_policy];
hjon6d49a8e2016-01-26 13:06:42 -080090 _tcpCandidatePolicy = [[self class] tcpCandidatePolicyForNativePolicy:
jtteh465faf02017-04-04 14:00:16 -070091 config.tcp_candidate_policy];
Honghai Zhang46007ae2016-06-03 16:31:32 -070092 _candidateNetworkPolicy = [[self class]
jtteh465faf02017-04-04 14:00:16 -070093 candidateNetworkPolicyForNativePolicy:config.candidate_network_policy];
Honghai Zhang3108fc92016-05-11 10:10:39 -070094 webrtc::PeerConnectionInterface::ContinualGatheringPolicy nativePolicy =
jtteh465faf02017-04-04 14:00:16 -070095 config.continual_gathering_policy;
Honghai Zhang3108fc92016-05-11 10:10:39 -070096 _continualGatheringPolicy =
97 [[self class] continualGatheringPolicyForNativePolicy:nativePolicy];
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +030098 _disableIPV6 = config.disable_ipv6;
99 _disableIPV6OnWiFi = config.disable_ipv6_on_wifi;
deadbeef2059bb32017-07-26 18:25:43 -0700100 _maxIPv6Networks = config.max_ipv6_networks;
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100101 _disableLinkLocalNetworks = config.disable_link_local_networks;
jtteh465faf02017-04-04 14:00:16 -0700102 _audioJitterBufferMaxPackets = config.audio_jitter_buffer_max_packets;
103 _audioJitterBufferFastAccelerate = config.audio_jitter_buffer_fast_accelerate;
104 _iceConnectionReceivingTimeout = config.ice_connection_receiving_timeout;
hjon6d49a8e2016-01-26 13:06:42 -0800105 _iceBackupCandidatePairPingInterval =
jtteh465faf02017-04-04 14:00:16 -0700106 config.ice_backup_candidate_pair_ping_interval;
tkchinab8f82f2016-01-27 17:50:11 -0800107 _keyType = RTCEncryptionKeyTypeECDSA;
jtteh465faf02017-04-04 14:00:16 -0700108 _iceCandidatePoolSize = config.ice_candidate_pool_size;
109 _shouldPruneTurnPorts = config.prune_turn_ports;
honghaizaf6b6e02016-07-11 15:09:26 -0700110 _shouldPresumeWritableWhenFullyRelayed =
jtteh465faf02017-04-04 14:00:16 -0700111 config.presume_writable_when_fully_relayed;
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700112 _shouldSurfaceIceCandidatesOnIceTransportTypeChanged =
113 config.surface_ice_candidates_on_ice_transport_type_changed;
jtteh465faf02017-04-04 14:00:16 -0700114 if (config.ice_check_min_interval) {
skvlada5d94ff2017-02-02 13:02:30 -0800115 _iceCheckMinInterval =
jtteh465faf02017-04-04 14:00:16 -0700116 [NSNumber numberWithInt:*config.ice_check_min_interval];
skvlada5d94ff2017-02-02 13:02:30 -0800117 }
Steve Anton8cb344a2018-02-27 15:34:53 -0800118 _sdpSemantics = [[self class] sdpSemanticsForNativeSdpSemantics:config.sdp_semantics];
Zeke Chinef1140e2017-10-27 15:42:08 -0700119 _turnCustomizer = config.turn_customizer;
Zhi Huangb57e1692018-06-12 11:41:11 -0700120 _activeResetSrtpParams = config.active_reset_srtp_params;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700121 if (config.crypto_options) {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +0200122 _cryptoOptions = [[RTC_OBJC_TYPE(RTCCryptoOptions) alloc]
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700123 initWithSrtpEnableGcmCryptoSuites:config.crypto_options->srtp
124 .enable_gcm_crypto_suites
125 srtpEnableAes128Sha1_32CryptoCipher:config.crypto_options->srtp
126 .enable_aes128_sha1_32_crypto_cipher
127 srtpEnableEncryptedRtpHeaderExtensions:config.crypto_options->srtp
128 .enable_encrypted_rtp_header_extensions
129 sframeRequireFrameEncryption:config.crypto_options->sframe
130 .require_frame_encryption];
131 }
Jiawei Oub1e47752018-11-13 23:48:19 -0800132 _rtcpAudioReportIntervalMs = config.audio_rtcp_report_interval_ms();
133 _rtcpVideoReportIntervalMs = config.video_rtcp_report_interval_ms();
philipel3eb84f02019-11-11 12:57:44 +0100134 _allowCodecSwitching = config.allow_codec_switching.value_or(false);
hjon6d49a8e2016-01-26 13:06:42 -0800135 }
136 return self;
137}
138
139- (NSString *)description {
Mirko Bonadeia81e9c82020-05-04 16:14:32 +0200140 static NSString *formatString = @"RTC_OBJC_TYPE(RTCConfiguration): "
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300141 @"{\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 +0200142 @"%d\n%@\n%d\n%d\n%d\n%d\n%d\n%@\n}\n";
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100143
Steve Anton8cb344a2018-02-27 15:34:53 -0800144 return [NSString
145 stringWithFormat:formatString,
146 _iceServers,
147 [[self class] stringForTransportPolicy:_iceTransportPolicy],
148 [[self class] stringForBundlePolicy:_bundlePolicy],
149 [[self class] stringForRtcpMuxPolicy:_rtcpMuxPolicy],
150 [[self class] stringForTcpCandidatePolicy:_tcpCandidatePolicy],
151 [[self class] stringForCandidateNetworkPolicy:_candidateNetworkPolicy],
152 [[self class] stringForContinualGatheringPolicy:_continualGatheringPolicy],
153 [[self class] stringForSdpSemantics:_sdpSemantics],
154 _audioJitterBufferMaxPackets,
155 _audioJitterBufferFastAccelerate,
156 _iceConnectionReceivingTimeout,
157 _iceBackupCandidatePairPingInterval,
158 _iceCandidatePoolSize,
159 _shouldPruneTurnPorts,
160 _shouldPresumeWritableWhenFullyRelayed,
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700161 _shouldSurfaceIceCandidatesOnIceTransportTypeChanged,
Steve Anton8cb344a2018-02-27 15:34:53 -0800162 _iceCheckMinInterval,
Steve Anton8cb344a2018-02-27 15:34:53 -0800163 _disableLinkLocalNetworks,
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300164 _disableIPV6,
165 _disableIPV6OnWiFi,
Zhi Huangb57e1692018-06-12 11:41:11 -0700166 _maxIPv6Networks,
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -0700167 _activeResetSrtpParams,
Taylor Brandstetter21c80322020-03-24 15:41:19 -0700168 _enableDscp];
hjon6d49a8e2016-01-26 13:06:42 -0800169}
170
171#pragma mark - Private
172
hbosa73ca562016-05-17 03:28:58 -0700173- (webrtc::PeerConnectionInterface::RTCConfiguration *)
174 createNativeConfiguration {
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200175 std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration>
Honghai Zhangf7ddc062016-09-01 15:34:01 -0700176 nativeConfig(new webrtc::PeerConnectionInterface::RTCConfiguration(
177 webrtc::PeerConnectionInterface::RTCConfigurationType::kAggressive));
hjon6d49a8e2016-01-26 13:06:42 -0800178
Taylor Brandstetter21c80322020-03-24 15:41:19 -0700179 nativeConfig->set_dscp(_enableDscp);
Mirko Bonadeia81e9c82020-05-04 16:14:32 +0200180 for (RTC_OBJC_TYPE(RTCIceServer) * iceServer in _iceServers) {
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200181 nativeConfig->servers.push_back(iceServer.nativeServer);
hjon6d49a8e2016-01-26 13:06:42 -0800182 }
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200183 nativeConfig->type =
hjon6d49a8e2016-01-26 13:06:42 -0800184 [[self class] nativeTransportsTypeForTransportPolicy:_iceTransportPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200185 nativeConfig->bundle_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800186 [[self class] nativeBundlePolicyForPolicy:_bundlePolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200187 nativeConfig->rtcp_mux_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800188 [[self class] nativeRtcpMuxPolicyForPolicy:_rtcpMuxPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200189 nativeConfig->tcp_candidate_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800190 [[self class] nativeTcpCandidatePolicyForPolicy:_tcpCandidatePolicy];
Honghai Zhang46007ae2016-06-03 16:31:32 -0700191 nativeConfig->candidate_network_policy = [[self class]
192 nativeCandidateNetworkPolicyForPolicy:_candidateNetworkPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200193 nativeConfig->continual_gathering_policy = [[self class]
Honghai Zhang3108fc92016-05-11 10:10:39 -0700194 nativeContinualGatheringPolicyForPolicy:_continualGatheringPolicy];
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300195 nativeConfig->disable_ipv6 = _disableIPV6;
196 nativeConfig->disable_ipv6_on_wifi = _disableIPV6OnWiFi;
deadbeef2059bb32017-07-26 18:25:43 -0700197 nativeConfig->max_ipv6_networks = _maxIPv6Networks;
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100198 nativeConfig->disable_link_local_networks = _disableLinkLocalNetworks;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200199 nativeConfig->audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets;
hayscc9f95002016-12-05 14:24:32 -0800200 nativeConfig->audio_jitter_buffer_fast_accelerate =
201 _audioJitterBufferFastAccelerate ? true : false;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200202 nativeConfig->ice_connection_receiving_timeout =
hjon6d49a8e2016-01-26 13:06:42 -0800203 _iceConnectionReceivingTimeout;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200204 nativeConfig->ice_backup_candidate_pair_ping_interval =
hjon6d49a8e2016-01-26 13:06:42 -0800205 _iceBackupCandidatePairPingInterval;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200206 rtc::KeyType keyType =
207 [[self class] nativeEncryptionKeyTypeForKeyType:_keyType];
Michael Iedemaccee56b2018-07-05 15:28:24 +0200208 if (_certificate != nullptr) {
209 // if offered a pemcert use it...
210 RTC_LOG(LS_INFO) << "Have configured cert - using it.";
211 std::string pem_private_key = [[_certificate private_key] UTF8String];
212 std::string pem_certificate = [[_certificate certificate] UTF8String];
213 rtc::RTCCertificatePEM pem = rtc::RTCCertificatePEM(pem_private_key, pem_certificate);
214 rtc::scoped_refptr<rtc::RTCCertificate> certificate = rtc::RTCCertificate::FromPEM(pem);
215 RTC_LOG(LS_INFO) << "Created cert from PEM strings.";
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200216 if (!certificate) {
Michael Iedemaccee56b2018-07-05 15:28:24 +0200217 RTC_LOG(LS_ERROR) << "Failed to generate certificate from PEM.";
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200218 return nullptr;
tkchinab8f82f2016-01-27 17:50:11 -0800219 }
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200220 nativeConfig->certificates.push_back(certificate);
Michael Iedemaccee56b2018-07-05 15:28:24 +0200221 } else {
222 RTC_LOG(LS_INFO) << "Don't have configured cert.";
223 // Generate non-default certificate.
224 if (keyType != rtc::KT_DEFAULT) {
225 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
226 rtc::RTCCertificateGenerator::GenerateCertificate(rtc::KeyParams(keyType),
227 absl::optional<uint64_t>());
228 if (!certificate) {
229 RTCLogError(@"Failed to generate certificate.");
230 return nullptr;
231 }
232 nativeConfig->certificates.push_back(certificate);
233 }
tkchinab8f82f2016-01-27 17:50:11 -0800234 }
deadbeefbe0c96f2016-05-18 16:20:14 -0700235 nativeConfig->ice_candidate_pool_size = _iceCandidatePoolSize;
honghaizaf6b6e02016-07-11 15:09:26 -0700236 nativeConfig->prune_turn_ports = _shouldPruneTurnPorts ? true : false;
Taylor Brandstettere9851112016-07-01 11:11:13 -0700237 nativeConfig->presume_writable_when_fully_relayed =
honghaizaf6b6e02016-07-11 15:09:26 -0700238 _shouldPresumeWritableWhenFullyRelayed ? true : false;
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700239 nativeConfig->surface_ice_candidates_on_ice_transport_type_changed =
240 _shouldSurfaceIceCandidatesOnIceTransportTypeChanged ? true : false;
skvlada5d94ff2017-02-02 13:02:30 -0800241 if (_iceCheckMinInterval != nil) {
Danil Chapovalov196100e2018-06-21 10:17:24 +0200242 nativeConfig->ice_check_min_interval = absl::optional<int>(_iceCheckMinInterval.intValue);
skvlada5d94ff2017-02-02 13:02:30 -0800243 }
Steve Anton8cb344a2018-02-27 15:34:53 -0800244 nativeConfig->sdp_semantics = [[self class] nativeSdpSemanticsForSdpSemantics:_sdpSemantics];
Zeke Chinef1140e2017-10-27 15:42:08 -0700245 if (_turnCustomizer) {
246 nativeConfig->turn_customizer = _turnCustomizer;
247 }
Zhi Huangb57e1692018-06-12 11:41:11 -0700248 nativeConfig->active_reset_srtp_params = _activeResetSrtpParams ? true : false;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700249 if (_cryptoOptions) {
250 webrtc::CryptoOptions nativeCryptoOptions;
251 nativeCryptoOptions.srtp.enable_gcm_crypto_suites =
252 _cryptoOptions.srtpEnableGcmCryptoSuites ? true : false;
253 nativeCryptoOptions.srtp.enable_aes128_sha1_32_crypto_cipher =
254 _cryptoOptions.srtpEnableAes128Sha1_32CryptoCipher ? true : false;
255 nativeCryptoOptions.srtp.enable_encrypted_rtp_header_extensions =
256 _cryptoOptions.srtpEnableEncryptedRtpHeaderExtensions ? true : false;
257 nativeCryptoOptions.sframe.require_frame_encryption =
258 _cryptoOptions.sframeRequireFrameEncryption ? true : false;
259 nativeConfig->crypto_options = absl::optional<webrtc::CryptoOptions>(nativeCryptoOptions);
260 }
Jiawei Oub1e47752018-11-13 23:48:19 -0800261 nativeConfig->set_audio_rtcp_report_interval_ms(_rtcpAudioReportIntervalMs);
262 nativeConfig->set_video_rtcp_report_interval_ms(_rtcpVideoReportIntervalMs);
philipel3eb84f02019-11-11 12:57:44 +0100263 nativeConfig->allow_codec_switching = _allowCodecSwitching;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200264 return nativeConfig.release();
hjon6d49a8e2016-01-26 13:06:42 -0800265}
266
hjon6d49a8e2016-01-26 13:06:42 -0800267+ (webrtc::PeerConnectionInterface::IceTransportsType)
268 nativeTransportsTypeForTransportPolicy:(RTCIceTransportPolicy)policy {
269 switch (policy) {
270 case RTCIceTransportPolicyNone:
271 return webrtc::PeerConnectionInterface::kNone;
272 case RTCIceTransportPolicyRelay:
273 return webrtc::PeerConnectionInterface::kRelay;
274 case RTCIceTransportPolicyNoHost:
275 return webrtc::PeerConnectionInterface::kNoHost;
276 case RTCIceTransportPolicyAll:
277 return webrtc::PeerConnectionInterface::kAll;
278 }
279}
280
281+ (RTCIceTransportPolicy)transportPolicyForTransportsType:
282 (webrtc::PeerConnectionInterface::IceTransportsType)nativeType {
283 switch (nativeType) {
284 case webrtc::PeerConnectionInterface::kNone:
285 return RTCIceTransportPolicyNone;
286 case webrtc::PeerConnectionInterface::kRelay:
287 return RTCIceTransportPolicyRelay;
288 case webrtc::PeerConnectionInterface::kNoHost:
289 return RTCIceTransportPolicyNoHost;
290 case webrtc::PeerConnectionInterface::kAll:
291 return RTCIceTransportPolicyAll;
292 }
293}
294
295+ (NSString *)stringForTransportPolicy:(RTCIceTransportPolicy)policy {
296 switch (policy) {
297 case RTCIceTransportPolicyNone:
298 return @"NONE";
299 case RTCIceTransportPolicyRelay:
300 return @"RELAY";
301 case RTCIceTransportPolicyNoHost:
302 return @"NO_HOST";
303 case RTCIceTransportPolicyAll:
304 return @"ALL";
305 }
306}
307
308+ (webrtc::PeerConnectionInterface::BundlePolicy)nativeBundlePolicyForPolicy:
309 (RTCBundlePolicy)policy {
310 switch (policy) {
311 case RTCBundlePolicyBalanced:
312 return webrtc::PeerConnectionInterface::kBundlePolicyBalanced;
313 case RTCBundlePolicyMaxCompat:
314 return webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat;
315 case RTCBundlePolicyMaxBundle:
316 return webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle;
317 }
318}
319
320+ (RTCBundlePolicy)bundlePolicyForNativePolicy:
321 (webrtc::PeerConnectionInterface::BundlePolicy)nativePolicy {
322 switch (nativePolicy) {
323 case webrtc::PeerConnectionInterface::kBundlePolicyBalanced:
324 return RTCBundlePolicyBalanced;
325 case webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat:
326 return RTCBundlePolicyMaxCompat;
327 case webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle:
328 return RTCBundlePolicyMaxBundle;
329 }
330}
331
332+ (NSString *)stringForBundlePolicy:(RTCBundlePolicy)policy {
333 switch (policy) {
334 case RTCBundlePolicyBalanced:
335 return @"BALANCED";
336 case RTCBundlePolicyMaxCompat:
337 return @"MAX_COMPAT";
338 case RTCBundlePolicyMaxBundle:
339 return @"MAX_BUNDLE";
340 }
341}
342
343+ (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativeRtcpMuxPolicyForPolicy:
344 (RTCRtcpMuxPolicy)policy {
345 switch (policy) {
346 case RTCRtcpMuxPolicyNegotiate:
347 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
348 case RTCRtcpMuxPolicyRequire:
349 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire;
350 }
351}
352
353+ (RTCRtcpMuxPolicy)rtcpMuxPolicyForNativePolicy:
354 (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativePolicy {
355 switch (nativePolicy) {
356 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate:
357 return RTCRtcpMuxPolicyNegotiate;
358 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire:
359 return RTCRtcpMuxPolicyRequire;
360 }
361}
362
363+ (NSString *)stringForRtcpMuxPolicy:(RTCRtcpMuxPolicy)policy {
364 switch (policy) {
365 case RTCRtcpMuxPolicyNegotiate:
366 return @"NEGOTIATE";
367 case RTCRtcpMuxPolicyRequire:
368 return @"REQUIRE";
369 }
370}
371
372+ (webrtc::PeerConnectionInterface::TcpCandidatePolicy)
373 nativeTcpCandidatePolicyForPolicy:(RTCTcpCandidatePolicy)policy {
374 switch (policy) {
375 case RTCTcpCandidatePolicyEnabled:
376 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled;
377 case RTCTcpCandidatePolicyDisabled:
378 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled;
379 }
380}
381
Honghai Zhang46007ae2016-06-03 16:31:32 -0700382+ (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)
383 nativeCandidateNetworkPolicyForPolicy:(RTCCandidateNetworkPolicy)policy {
384 switch (policy) {
385 case RTCCandidateNetworkPolicyAll:
386 return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll;
387 case RTCCandidateNetworkPolicyLowCost:
388 return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
389 }
390}
391
hjon6d49a8e2016-01-26 13:06:42 -0800392+ (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativePolicy:
393 (webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativePolicy {
394 switch (nativePolicy) {
395 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled:
396 return RTCTcpCandidatePolicyEnabled;
397 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled:
398 return RTCTcpCandidatePolicyDisabled;
399 }
400}
401
402+ (NSString *)stringForTcpCandidatePolicy:(RTCTcpCandidatePolicy)policy {
403 switch (policy) {
404 case RTCTcpCandidatePolicyEnabled:
405 return @"TCP_ENABLED";
406 case RTCTcpCandidatePolicyDisabled:
407 return @"TCP_DISABLED";
408 }
409}
410
Honghai Zhang46007ae2016-06-03 16:31:32 -0700411+ (RTCCandidateNetworkPolicy)candidateNetworkPolicyForNativePolicy:
412 (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)nativePolicy {
413 switch (nativePolicy) {
414 case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll:
415 return RTCCandidateNetworkPolicyAll;
416 case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost:
417 return RTCCandidateNetworkPolicyLowCost;
418 }
419}
420
421+ (NSString *)stringForCandidateNetworkPolicy:
422 (RTCCandidateNetworkPolicy)policy {
423 switch (policy) {
424 case RTCCandidateNetworkPolicyAll:
425 return @"CANDIDATE_ALL_NETWORKS";
426 case RTCCandidateNetworkPolicyLowCost:
427 return @"CANDIDATE_LOW_COST_NETWORKS";
428 }
429}
430
Honghai Zhang3108fc92016-05-11 10:10:39 -0700431+ (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)
432 nativeContinualGatheringPolicyForPolicy:
433 (RTCContinualGatheringPolicy)policy {
434 switch (policy) {
435 case RTCContinualGatheringPolicyGatherOnce:
436 return webrtc::PeerConnectionInterface::GATHER_ONCE;
437 case RTCContinualGatheringPolicyGatherContinually:
438 return webrtc::PeerConnectionInterface::GATHER_CONTINUALLY;
439 }
440}
441
442+ (RTCContinualGatheringPolicy)continualGatheringPolicyForNativePolicy:
443 (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)nativePolicy {
444 switch (nativePolicy) {
445 case webrtc::PeerConnectionInterface::GATHER_ONCE:
446 return RTCContinualGatheringPolicyGatherOnce;
447 case webrtc::PeerConnectionInterface::GATHER_CONTINUALLY:
448 return RTCContinualGatheringPolicyGatherContinually;
449 }
450}
451
452+ (NSString *)stringForContinualGatheringPolicy:
453 (RTCContinualGatheringPolicy)policy {
454 switch (policy) {
455 case RTCContinualGatheringPolicyGatherOnce:
456 return @"GATHER_ONCE";
457 case RTCContinualGatheringPolicyGatherContinually:
458 return @"GATHER_CONTINUALLY";
459 }
460}
461
hbosf9da44d2016-06-09 03:18:28 -0700462+ (rtc::KeyType)nativeEncryptionKeyTypeForKeyType:
463 (RTCEncryptionKeyType)keyType {
464 switch (keyType) {
465 case RTCEncryptionKeyTypeRSA:
466 return rtc::KT_RSA;
467 case RTCEncryptionKeyTypeECDSA:
468 return rtc::KT_ECDSA;
469 }
470}
471
Steve Anton8cb344a2018-02-27 15:34:53 -0800472+ (webrtc::SdpSemantics)nativeSdpSemanticsForSdpSemantics:(RTCSdpSemantics)sdpSemantics {
473 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800474 case RTCSdpSemanticsPlanB:
475 return webrtc::SdpSemantics::kPlanB;
476 case RTCSdpSemanticsUnifiedPlan:
477 return webrtc::SdpSemantics::kUnifiedPlan;
478 }
479}
480
481+ (RTCSdpSemantics)sdpSemanticsForNativeSdpSemantics:(webrtc::SdpSemantics)sdpSemantics {
482 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800483 case webrtc::SdpSemantics::kPlanB:
484 return RTCSdpSemanticsPlanB;
485 case webrtc::SdpSemantics::kUnifiedPlan:
486 return RTCSdpSemanticsUnifiedPlan;
487 }
488}
489
490+ (NSString *)stringForSdpSemantics:(RTCSdpSemantics)sdpSemantics {
491 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800492 case RTCSdpSemanticsPlanB:
493 return @"PLAN_B";
494 case RTCSdpSemanticsUnifiedPlan:
495 return @"UNIFIED_PLAN";
496 }
497}
498
hjon6d49a8e2016-01-26 13:06:42 -0800499@end