blob: eeb94939f3d12a1a98140e25f1e303d6848edf57 [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
23@implementation RTCConfiguration
24
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;
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -070055@synthesize useMediaTransport = _useMediaTransport;
Bjorn Mellema9bbd862018-11-02 09:07:48 -070056@synthesize useMediaTransportForDataChannels = _useMediaTransportForDataChannels;
Benjamin Wright8c27cca2018-10-25 10:16:44 -070057@synthesize cryptoOptions = _cryptoOptions;
Jiawei Oub1e47752018-11-13 23:48:19 -080058@synthesize rtcpAudioReportIntervalMs = _rtcpAudioReportIntervalMs;
59@synthesize rtcpVideoReportIntervalMs = _rtcpVideoReportIntervalMs;
hjon6d49a8e2016-01-26 13:06:42 -080060
61- (instancetype)init {
jtteh4eeb5372017-04-03 15:06:37 -070062 // Copy defaults.
Yuriy Pavlyshak8cec4fb2018-09-07 16:43:31 +020063 webrtc::PeerConnectionInterface::RTCConfiguration config;
jtteh465faf02017-04-04 14:00:16 -070064 return [self initWithNativeConfiguration:config];
jtteh4eeb5372017-04-03 15:06:37 -070065}
66
67- (instancetype)initWithNativeConfiguration:
jtteh465faf02017-04-04 14:00:16 -070068 (const webrtc::PeerConnectionInterface::RTCConfiguration &)config {
hjon6d49a8e2016-01-26 13:06:42 -080069 if (self = [super init]) {
Taylor Brandstetter21c80322020-03-24 15:41:19 -070070 _enableDscp = config.dscp();
jtteh4eeb5372017-04-03 15:06:37 -070071 NSMutableArray *iceServers = [NSMutableArray array];
jtteh465faf02017-04-04 14:00:16 -070072 for (const webrtc::PeerConnectionInterface::IceServer& server : config.servers) {
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 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) {
125 _cryptoOptions = [[RTCCryptoOptions alloc]
126 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 }
Jiawei Oub1e47752018-11-13 23:48:19 -0800135 _rtcpAudioReportIntervalMs = config.audio_rtcp_report_interval_ms();
136 _rtcpVideoReportIntervalMs = config.video_rtcp_report_interval_ms();
philipel3eb84f02019-11-11 12:57:44 +0100137 _allowCodecSwitching = config.allow_codec_switching.value_or(false);
hjon6d49a8e2016-01-26 13:06:42 -0800138 }
139 return self;
140}
141
142- (NSString *)description {
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300143 static NSString *formatString = @"RTCConfiguration: "
144 @"{\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%d\n%d\n%d\n%d\n%d\n%d\n"
Taylor Brandstetter21c80322020-03-24 15:41:19 -0700145 @"%d\n%@\n%d\n%d\n%d\n%d\n%d\n%@\n%d\n}\n";
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100146
Steve Anton8cb344a2018-02-27 15:34:53 -0800147 return [NSString
148 stringWithFormat:formatString,
149 _iceServers,
150 [[self class] stringForTransportPolicy:_iceTransportPolicy],
151 [[self class] stringForBundlePolicy:_bundlePolicy],
152 [[self class] stringForRtcpMuxPolicy:_rtcpMuxPolicy],
153 [[self class] stringForTcpCandidatePolicy:_tcpCandidatePolicy],
154 [[self class] stringForCandidateNetworkPolicy:_candidateNetworkPolicy],
155 [[self class] stringForContinualGatheringPolicy:_continualGatheringPolicy],
156 [[self class] stringForSdpSemantics:_sdpSemantics],
157 _audioJitterBufferMaxPackets,
158 _audioJitterBufferFastAccelerate,
159 _iceConnectionReceivingTimeout,
160 _iceBackupCandidatePairPingInterval,
161 _iceCandidatePoolSize,
162 _shouldPruneTurnPorts,
163 _shouldPresumeWritableWhenFullyRelayed,
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700164 _shouldSurfaceIceCandidatesOnIceTransportTypeChanged,
Steve Anton8cb344a2018-02-27 15:34:53 -0800165 _iceCheckMinInterval,
Steve Anton8cb344a2018-02-27 15:34:53 -0800166 _disableLinkLocalNetworks,
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300167 _disableIPV6,
168 _disableIPV6OnWiFi,
Zhi Huangb57e1692018-06-12 11:41:11 -0700169 _maxIPv6Networks,
Piotr (Peter) Slatalae0c2e972018-10-08 09:43:21 -0700170 _activeResetSrtpParams,
Taylor Brandstetter21c80322020-03-24 15:41:19 -0700171 _useMediaTransport,
172 _enableDscp];
hjon6d49a8e2016-01-26 13:06:42 -0800173}
174
175#pragma mark - Private
176
hbosa73ca562016-05-17 03:28:58 -0700177- (webrtc::PeerConnectionInterface::RTCConfiguration *)
178 createNativeConfiguration {
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200179 std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration>
Honghai Zhangf7ddc062016-09-01 15:34:01 -0700180 nativeConfig(new webrtc::PeerConnectionInterface::RTCConfiguration(
181 webrtc::PeerConnectionInterface::RTCConfigurationType::kAggressive));
hjon6d49a8e2016-01-26 13:06:42 -0800182
Taylor Brandstetter21c80322020-03-24 15:41:19 -0700183 nativeConfig->set_dscp(_enableDscp);
hjon6d49a8e2016-01-26 13:06:42 -0800184 for (RTCIceServer *iceServer in _iceServers) {
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200185 nativeConfig->servers.push_back(iceServer.nativeServer);
hjon6d49a8e2016-01-26 13:06:42 -0800186 }
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200187 nativeConfig->type =
hjon6d49a8e2016-01-26 13:06:42 -0800188 [[self class] nativeTransportsTypeForTransportPolicy:_iceTransportPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200189 nativeConfig->bundle_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800190 [[self class] nativeBundlePolicyForPolicy:_bundlePolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200191 nativeConfig->rtcp_mux_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800192 [[self class] nativeRtcpMuxPolicyForPolicy:_rtcpMuxPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200193 nativeConfig->tcp_candidate_policy =
hjon6d49a8e2016-01-26 13:06:42 -0800194 [[self class] nativeTcpCandidatePolicyForPolicy:_tcpCandidatePolicy];
Honghai Zhang46007ae2016-06-03 16:31:32 -0700195 nativeConfig->candidate_network_policy = [[self class]
196 nativeCandidateNetworkPolicyForPolicy:_candidateNetworkPolicy];
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200197 nativeConfig->continual_gathering_policy = [[self class]
Honghai Zhang3108fc92016-05-11 10:10:39 -0700198 nativeContinualGatheringPolicyForPolicy:_continualGatheringPolicy];
Uladzislau Sushabf0d0c12018-11-05 12:48:35 +0300199 nativeConfig->disable_ipv6 = _disableIPV6;
200 nativeConfig->disable_ipv6_on_wifi = _disableIPV6OnWiFi;
deadbeef2059bb32017-07-26 18:25:43 -0700201 nativeConfig->max_ipv6_networks = _maxIPv6Networks;
Daniel Lazarenko2870b0a2018-01-25 10:30:22 +0100202 nativeConfig->disable_link_local_networks = _disableLinkLocalNetworks;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200203 nativeConfig->audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets;
hayscc9f95002016-12-05 14:24:32 -0800204 nativeConfig->audio_jitter_buffer_fast_accelerate =
205 _audioJitterBufferFastAccelerate ? true : false;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200206 nativeConfig->ice_connection_receiving_timeout =
hjon6d49a8e2016-01-26 13:06:42 -0800207 _iceConnectionReceivingTimeout;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200208 nativeConfig->ice_backup_candidate_pair_ping_interval =
hjon6d49a8e2016-01-26 13:06:42 -0800209 _iceBackupCandidatePairPingInterval;
Piotr (Peter) Slatala88d8d7d2018-10-26 15:06:17 -0700210 nativeConfig->use_media_transport = _useMediaTransport;
Bjorn Mellema9bbd862018-11-02 09:07:48 -0700211 nativeConfig->use_media_transport_for_data_channels = _useMediaTransportForDataChannels;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200212 rtc::KeyType keyType =
213 [[self class] nativeEncryptionKeyTypeForKeyType:_keyType];
Michael Iedemaccee56b2018-07-05 15:28:24 +0200214 if (_certificate != nullptr) {
215 // if offered a pemcert use it...
216 RTC_LOG(LS_INFO) << "Have configured cert - using it.";
217 std::string pem_private_key = [[_certificate private_key] UTF8String];
218 std::string pem_certificate = [[_certificate certificate] UTF8String];
219 rtc::RTCCertificatePEM pem = rtc::RTCCertificatePEM(pem_private_key, pem_certificate);
220 rtc::scoped_refptr<rtc::RTCCertificate> certificate = rtc::RTCCertificate::FromPEM(pem);
221 RTC_LOG(LS_INFO) << "Created cert from PEM strings.";
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200222 if (!certificate) {
Michael Iedemaccee56b2018-07-05 15:28:24 +0200223 RTC_LOG(LS_ERROR) << "Failed to generate certificate from PEM.";
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200224 return nullptr;
tkchinab8f82f2016-01-27 17:50:11 -0800225 }
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200226 nativeConfig->certificates.push_back(certificate);
Michael Iedemaccee56b2018-07-05 15:28:24 +0200227 } else {
228 RTC_LOG(LS_INFO) << "Don't have configured cert.";
229 // Generate non-default certificate.
230 if (keyType != rtc::KT_DEFAULT) {
231 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
232 rtc::RTCCertificateGenerator::GenerateCertificate(rtc::KeyParams(keyType),
233 absl::optional<uint64_t>());
234 if (!certificate) {
235 RTCLogError(@"Failed to generate certificate.");
236 return nullptr;
237 }
238 nativeConfig->certificates.push_back(certificate);
239 }
tkchinab8f82f2016-01-27 17:50:11 -0800240 }
deadbeefbe0c96f2016-05-18 16:20:14 -0700241 nativeConfig->ice_candidate_pool_size = _iceCandidatePoolSize;
honghaizaf6b6e02016-07-11 15:09:26 -0700242 nativeConfig->prune_turn_ports = _shouldPruneTurnPorts ? true : false;
Taylor Brandstettere9851112016-07-01 11:11:13 -0700243 nativeConfig->presume_writable_when_fully_relayed =
honghaizaf6b6e02016-07-11 15:09:26 -0700244 _shouldPresumeWritableWhenFullyRelayed ? true : false;
Qingsi Wang1fe119f2019-05-31 16:55:33 -0700245 nativeConfig->surface_ice_candidates_on_ice_transport_type_changed =
246 _shouldSurfaceIceCandidatesOnIceTransportTypeChanged ? true : false;
skvlada5d94ff2017-02-02 13:02:30 -0800247 if (_iceCheckMinInterval != nil) {
Danil Chapovalov196100e2018-06-21 10:17:24 +0200248 nativeConfig->ice_check_min_interval = absl::optional<int>(_iceCheckMinInterval.intValue);
skvlada5d94ff2017-02-02 13:02:30 -0800249 }
Steve Anton8cb344a2018-02-27 15:34:53 -0800250 nativeConfig->sdp_semantics = [[self class] nativeSdpSemanticsForSdpSemantics:_sdpSemantics];
Zeke Chinef1140e2017-10-27 15:42:08 -0700251 if (_turnCustomizer) {
252 nativeConfig->turn_customizer = _turnCustomizer;
253 }
Zhi Huangb57e1692018-06-12 11:41:11 -0700254 nativeConfig->active_reset_srtp_params = _activeResetSrtpParams ? true : false;
Benjamin Wright8c27cca2018-10-25 10:16:44 -0700255 if (_cryptoOptions) {
256 webrtc::CryptoOptions nativeCryptoOptions;
257 nativeCryptoOptions.srtp.enable_gcm_crypto_suites =
258 _cryptoOptions.srtpEnableGcmCryptoSuites ? true : false;
259 nativeCryptoOptions.srtp.enable_aes128_sha1_32_crypto_cipher =
260 _cryptoOptions.srtpEnableAes128Sha1_32CryptoCipher ? true : false;
261 nativeCryptoOptions.srtp.enable_encrypted_rtp_header_extensions =
262 _cryptoOptions.srtpEnableEncryptedRtpHeaderExtensions ? true : false;
263 nativeCryptoOptions.sframe.require_frame_encryption =
264 _cryptoOptions.sframeRequireFrameEncryption ? true : false;
265 nativeConfig->crypto_options = absl::optional<webrtc::CryptoOptions>(nativeCryptoOptions);
266 }
Jiawei Oub1e47752018-11-13 23:48:19 -0800267 nativeConfig->set_audio_rtcp_report_interval_ms(_rtcpAudioReportIntervalMs);
268 nativeConfig->set_video_rtcp_report_interval_ms(_rtcpVideoReportIntervalMs);
philipel3eb84f02019-11-11 12:57:44 +0100269 nativeConfig->allow_codec_switching = _allowCodecSwitching;
Henrik Boströme06c2dd2016-05-13 13:50:38 +0200270 return nativeConfig.release();
hjon6d49a8e2016-01-26 13:06:42 -0800271}
272
hjon6d49a8e2016-01-26 13:06:42 -0800273+ (webrtc::PeerConnectionInterface::IceTransportsType)
274 nativeTransportsTypeForTransportPolicy:(RTCIceTransportPolicy)policy {
275 switch (policy) {
276 case RTCIceTransportPolicyNone:
277 return webrtc::PeerConnectionInterface::kNone;
278 case RTCIceTransportPolicyRelay:
279 return webrtc::PeerConnectionInterface::kRelay;
280 case RTCIceTransportPolicyNoHost:
281 return webrtc::PeerConnectionInterface::kNoHost;
282 case RTCIceTransportPolicyAll:
283 return webrtc::PeerConnectionInterface::kAll;
284 }
285}
286
287+ (RTCIceTransportPolicy)transportPolicyForTransportsType:
288 (webrtc::PeerConnectionInterface::IceTransportsType)nativeType {
289 switch (nativeType) {
290 case webrtc::PeerConnectionInterface::kNone:
291 return RTCIceTransportPolicyNone;
292 case webrtc::PeerConnectionInterface::kRelay:
293 return RTCIceTransportPolicyRelay;
294 case webrtc::PeerConnectionInterface::kNoHost:
295 return RTCIceTransportPolicyNoHost;
296 case webrtc::PeerConnectionInterface::kAll:
297 return RTCIceTransportPolicyAll;
298 }
299}
300
301+ (NSString *)stringForTransportPolicy:(RTCIceTransportPolicy)policy {
302 switch (policy) {
303 case RTCIceTransportPolicyNone:
304 return @"NONE";
305 case RTCIceTransportPolicyRelay:
306 return @"RELAY";
307 case RTCIceTransportPolicyNoHost:
308 return @"NO_HOST";
309 case RTCIceTransportPolicyAll:
310 return @"ALL";
311 }
312}
313
314+ (webrtc::PeerConnectionInterface::BundlePolicy)nativeBundlePolicyForPolicy:
315 (RTCBundlePolicy)policy {
316 switch (policy) {
317 case RTCBundlePolicyBalanced:
318 return webrtc::PeerConnectionInterface::kBundlePolicyBalanced;
319 case RTCBundlePolicyMaxCompat:
320 return webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat;
321 case RTCBundlePolicyMaxBundle:
322 return webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle;
323 }
324}
325
326+ (RTCBundlePolicy)bundlePolicyForNativePolicy:
327 (webrtc::PeerConnectionInterface::BundlePolicy)nativePolicy {
328 switch (nativePolicy) {
329 case webrtc::PeerConnectionInterface::kBundlePolicyBalanced:
330 return RTCBundlePolicyBalanced;
331 case webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat:
332 return RTCBundlePolicyMaxCompat;
333 case webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle:
334 return RTCBundlePolicyMaxBundle;
335 }
336}
337
338+ (NSString *)stringForBundlePolicy:(RTCBundlePolicy)policy {
339 switch (policy) {
340 case RTCBundlePolicyBalanced:
341 return @"BALANCED";
342 case RTCBundlePolicyMaxCompat:
343 return @"MAX_COMPAT";
344 case RTCBundlePolicyMaxBundle:
345 return @"MAX_BUNDLE";
346 }
347}
348
349+ (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativeRtcpMuxPolicyForPolicy:
350 (RTCRtcpMuxPolicy)policy {
351 switch (policy) {
352 case RTCRtcpMuxPolicyNegotiate:
353 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
354 case RTCRtcpMuxPolicyRequire:
355 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire;
356 }
357}
358
359+ (RTCRtcpMuxPolicy)rtcpMuxPolicyForNativePolicy:
360 (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativePolicy {
361 switch (nativePolicy) {
362 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate:
363 return RTCRtcpMuxPolicyNegotiate;
364 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire:
365 return RTCRtcpMuxPolicyRequire;
366 }
367}
368
369+ (NSString *)stringForRtcpMuxPolicy:(RTCRtcpMuxPolicy)policy {
370 switch (policy) {
371 case RTCRtcpMuxPolicyNegotiate:
372 return @"NEGOTIATE";
373 case RTCRtcpMuxPolicyRequire:
374 return @"REQUIRE";
375 }
376}
377
378+ (webrtc::PeerConnectionInterface::TcpCandidatePolicy)
379 nativeTcpCandidatePolicyForPolicy:(RTCTcpCandidatePolicy)policy {
380 switch (policy) {
381 case RTCTcpCandidatePolicyEnabled:
382 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled;
383 case RTCTcpCandidatePolicyDisabled:
384 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled;
385 }
386}
387
Honghai Zhang46007ae2016-06-03 16:31:32 -0700388+ (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)
389 nativeCandidateNetworkPolicyForPolicy:(RTCCandidateNetworkPolicy)policy {
390 switch (policy) {
391 case RTCCandidateNetworkPolicyAll:
392 return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll;
393 case RTCCandidateNetworkPolicyLowCost:
394 return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
395 }
396}
397
hjon6d49a8e2016-01-26 13:06:42 -0800398+ (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativePolicy:
399 (webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativePolicy {
400 switch (nativePolicy) {
401 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled:
402 return RTCTcpCandidatePolicyEnabled;
403 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled:
404 return RTCTcpCandidatePolicyDisabled;
405 }
406}
407
408+ (NSString *)stringForTcpCandidatePolicy:(RTCTcpCandidatePolicy)policy {
409 switch (policy) {
410 case RTCTcpCandidatePolicyEnabled:
411 return @"TCP_ENABLED";
412 case RTCTcpCandidatePolicyDisabled:
413 return @"TCP_DISABLED";
414 }
415}
416
Honghai Zhang46007ae2016-06-03 16:31:32 -0700417+ (RTCCandidateNetworkPolicy)candidateNetworkPolicyForNativePolicy:
418 (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)nativePolicy {
419 switch (nativePolicy) {
420 case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll:
421 return RTCCandidateNetworkPolicyAll;
422 case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost:
423 return RTCCandidateNetworkPolicyLowCost;
424 }
425}
426
427+ (NSString *)stringForCandidateNetworkPolicy:
428 (RTCCandidateNetworkPolicy)policy {
429 switch (policy) {
430 case RTCCandidateNetworkPolicyAll:
431 return @"CANDIDATE_ALL_NETWORKS";
432 case RTCCandidateNetworkPolicyLowCost:
433 return @"CANDIDATE_LOW_COST_NETWORKS";
434 }
435}
436
Honghai Zhang3108fc92016-05-11 10:10:39 -0700437+ (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)
438 nativeContinualGatheringPolicyForPolicy:
439 (RTCContinualGatheringPolicy)policy {
440 switch (policy) {
441 case RTCContinualGatheringPolicyGatherOnce:
442 return webrtc::PeerConnectionInterface::GATHER_ONCE;
443 case RTCContinualGatheringPolicyGatherContinually:
444 return webrtc::PeerConnectionInterface::GATHER_CONTINUALLY;
445 }
446}
447
448+ (RTCContinualGatheringPolicy)continualGatheringPolicyForNativePolicy:
449 (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)nativePolicy {
450 switch (nativePolicy) {
451 case webrtc::PeerConnectionInterface::GATHER_ONCE:
452 return RTCContinualGatheringPolicyGatherOnce;
453 case webrtc::PeerConnectionInterface::GATHER_CONTINUALLY:
454 return RTCContinualGatheringPolicyGatherContinually;
455 }
456}
457
458+ (NSString *)stringForContinualGatheringPolicy:
459 (RTCContinualGatheringPolicy)policy {
460 switch (policy) {
461 case RTCContinualGatheringPolicyGatherOnce:
462 return @"GATHER_ONCE";
463 case RTCContinualGatheringPolicyGatherContinually:
464 return @"GATHER_CONTINUALLY";
465 }
466}
467
hbosf9da44d2016-06-09 03:18:28 -0700468+ (rtc::KeyType)nativeEncryptionKeyTypeForKeyType:
469 (RTCEncryptionKeyType)keyType {
470 switch (keyType) {
471 case RTCEncryptionKeyTypeRSA:
472 return rtc::KT_RSA;
473 case RTCEncryptionKeyTypeECDSA:
474 return rtc::KT_ECDSA;
475 }
476}
477
Steve Anton8cb344a2018-02-27 15:34:53 -0800478+ (webrtc::SdpSemantics)nativeSdpSemanticsForSdpSemantics:(RTCSdpSemantics)sdpSemantics {
479 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800480 case RTCSdpSemanticsPlanB:
481 return webrtc::SdpSemantics::kPlanB;
482 case RTCSdpSemanticsUnifiedPlan:
483 return webrtc::SdpSemantics::kUnifiedPlan;
484 }
485}
486
487+ (RTCSdpSemantics)sdpSemanticsForNativeSdpSemantics:(webrtc::SdpSemantics)sdpSemantics {
488 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800489 case webrtc::SdpSemantics::kPlanB:
490 return RTCSdpSemanticsPlanB;
491 case webrtc::SdpSemantics::kUnifiedPlan:
492 return RTCSdpSemanticsUnifiedPlan;
493 }
494}
495
496+ (NSString *)stringForSdpSemantics:(RTCSdpSemantics)sdpSemantics {
497 switch (sdpSemantics) {
Steve Anton8cb344a2018-02-27 15:34:53 -0800498 case RTCSdpSemanticsPlanB:
499 return @"PLAN_B";
500 case RTCSdpSemanticsUnifiedPlan:
501 return @"UNIFIED_PLAN";
502 }
503}
504
hjon6d49a8e2016-01-26 13:06:42 -0800505@end