Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: webrtc/sdk/objc/Framework/Classes/PeerConnection/RTCConfiguration.mm

Issue 2890513002: Revert of Split iOS sdk in to separate targets (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
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
11 #import "RTCConfiguration+Private.h"
12
13 #include <memory>
14
15 #import "RTCIceServer+Private.h"
16 #import "WebRTC/RTCLogging.h"
17
18 #include "webrtc/base/rtccertificategenerator.h"
19 #include "webrtc/base/sslidentity.h"
20
21 @implementation RTCConfiguration
22
23 @synthesize iceServers = _iceServers;
24 @synthesize iceTransportPolicy = _iceTransportPolicy;
25 @synthesize bundlePolicy = _bundlePolicy;
26 @synthesize rtcpMuxPolicy = _rtcpMuxPolicy;
27 @synthesize tcpCandidatePolicy = _tcpCandidatePolicy;
28 @synthesize candidateNetworkPolicy = _candidateNetworkPolicy;
29 @synthesize continualGatheringPolicy = _continualGatheringPolicy;
30 @synthesize audioJitterBufferMaxPackets = _audioJitterBufferMaxPackets;
31 @synthesize audioJitterBufferFastAccelerate = _audioJitterBufferFastAccelerate;
32 @synthesize iceConnectionReceivingTimeout = _iceConnectionReceivingTimeout;
33 @synthesize iceBackupCandidatePairPingInterval =
34 _iceBackupCandidatePairPingInterval;
35 @synthesize keyType = _keyType;
36 @synthesize iceCandidatePoolSize = _iceCandidatePoolSize;
37 @synthesize shouldPruneTurnPorts = _shouldPruneTurnPorts;
38 @synthesize shouldPresumeWritableWhenFullyRelayed =
39 _shouldPresumeWritableWhenFullyRelayed;
40 @synthesize iceCheckMinInterval = _iceCheckMinInterval;
41
42 - (instancetype)init {
43 // Copy defaults.
44 webrtc::PeerConnectionInterface::RTCConfiguration config(
45 webrtc::PeerConnectionInterface::RTCConfigurationType::kAggressive);
46 return [self initWithNativeConfiguration:config];
47 }
48
49 - (instancetype)initWithNativeConfiguration:
50 (const webrtc::PeerConnectionInterface::RTCConfiguration &)config {
51 if (self = [super init]) {
52 NSMutableArray *iceServers = [NSMutableArray array];
53 for (const webrtc::PeerConnectionInterface::IceServer& server : config.serve rs) {
54 RTCIceServer *iceServer = [[RTCIceServer alloc] initWithNativeServer:serve r];
55 [iceServers addObject:iceServer];
56 }
57 _iceServers = iceServers;
58 _iceTransportPolicy =
59 [[self class] transportPolicyForTransportsType:config.type];
60 _bundlePolicy =
61 [[self class] bundlePolicyForNativePolicy:config.bundle_policy];
62 _rtcpMuxPolicy =
63 [[self class] rtcpMuxPolicyForNativePolicy:config.rtcp_mux_policy];
64 _tcpCandidatePolicy = [[self class] tcpCandidatePolicyForNativePolicy:
65 config.tcp_candidate_policy];
66 _candidateNetworkPolicy = [[self class]
67 candidateNetworkPolicyForNativePolicy:config.candidate_network_policy];
68 webrtc::PeerConnectionInterface::ContinualGatheringPolicy nativePolicy =
69 config.continual_gathering_policy;
70 _continualGatheringPolicy =
71 [[self class] continualGatheringPolicyForNativePolicy:nativePolicy];
72 _audioJitterBufferMaxPackets = config.audio_jitter_buffer_max_packets;
73 _audioJitterBufferFastAccelerate = config.audio_jitter_buffer_fast_accelerat e;
74 _iceConnectionReceivingTimeout = config.ice_connection_receiving_timeout;
75 _iceBackupCandidatePairPingInterval =
76 config.ice_backup_candidate_pair_ping_interval;
77 _keyType = RTCEncryptionKeyTypeECDSA;
78 _iceCandidatePoolSize = config.ice_candidate_pool_size;
79 _shouldPruneTurnPorts = config.prune_turn_ports;
80 _shouldPresumeWritableWhenFullyRelayed =
81 config.presume_writable_when_fully_relayed;
82 if (config.ice_check_min_interval) {
83 _iceCheckMinInterval =
84 [NSNumber numberWithInt:*config.ice_check_min_interval];
85 }
86 }
87 return self;
88 }
89
90 - (NSString *)description {
91 return [NSString stringWithFormat:
92 @"RTCConfiguration: {\n%@\n%@\n%@\n%@\n%@\n%@\n%@\n%d\n%d\n%d\n%d\n%d\n%d\ n%d\n%@\n}\n",
93 _iceServers,
94 [[self class] stringForTransportPolicy:_iceTransportPolicy],
95 [[self class] stringForBundlePolicy:_bundlePolicy],
96 [[self class] stringForRtcpMuxPolicy:_rtcpMuxPolicy],
97 [[self class] stringForTcpCandidatePolicy:_tcpCandidatePolicy],
98 [[self class] stringForCandidateNetworkPolicy:_candidateNetworkPolicy],
99 [[self class]
100 stringForContinualGatheringPolicy:_continualGatheringPolicy],
101 _audioJitterBufferMaxPackets,
102 _audioJitterBufferFastAccelerate,
103 _iceConnectionReceivingTimeout,
104 _iceBackupCandidatePairPingInterval,
105 _iceCandidatePoolSize,
106 _shouldPruneTurnPorts,
107 _shouldPresumeWritableWhenFullyRelayed,
108 _iceCheckMinInterval];
109 }
110
111 #pragma mark - Private
112
113 - (webrtc::PeerConnectionInterface::RTCConfiguration *)
114 createNativeConfiguration {
115 std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration>
116 nativeConfig(new webrtc::PeerConnectionInterface::RTCConfiguration(
117 webrtc::PeerConnectionInterface::RTCConfigurationType::kAggressive));
118
119 for (RTCIceServer *iceServer in _iceServers) {
120 nativeConfig->servers.push_back(iceServer.nativeServer);
121 }
122 nativeConfig->type =
123 [[self class] nativeTransportsTypeForTransportPolicy:_iceTransportPolicy];
124 nativeConfig->bundle_policy =
125 [[self class] nativeBundlePolicyForPolicy:_bundlePolicy];
126 nativeConfig->rtcp_mux_policy =
127 [[self class] nativeRtcpMuxPolicyForPolicy:_rtcpMuxPolicy];
128 nativeConfig->tcp_candidate_policy =
129 [[self class] nativeTcpCandidatePolicyForPolicy:_tcpCandidatePolicy];
130 nativeConfig->candidate_network_policy = [[self class]
131 nativeCandidateNetworkPolicyForPolicy:_candidateNetworkPolicy];
132 nativeConfig->continual_gathering_policy = [[self class]
133 nativeContinualGatheringPolicyForPolicy:_continualGatheringPolicy];
134 nativeConfig->audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets;
135 nativeConfig->audio_jitter_buffer_fast_accelerate =
136 _audioJitterBufferFastAccelerate ? true : false;
137 nativeConfig->ice_connection_receiving_timeout =
138 _iceConnectionReceivingTimeout;
139 nativeConfig->ice_backup_candidate_pair_ping_interval =
140 _iceBackupCandidatePairPingInterval;
141 rtc::KeyType keyType =
142 [[self class] nativeEncryptionKeyTypeForKeyType:_keyType];
143 // Generate non-default certificate.
144 if (keyType != rtc::KT_DEFAULT) {
145 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
146 rtc::RTCCertificateGenerator::GenerateCertificate(
147 rtc::KeyParams(keyType), rtc::Optional<uint64_t>());
148 if (!certificate) {
149 RTCLogError(@"Failed to generate certificate.");
150 return nullptr;
151 }
152 nativeConfig->certificates.push_back(certificate);
153 }
154 nativeConfig->ice_candidate_pool_size = _iceCandidatePoolSize;
155 nativeConfig->prune_turn_ports = _shouldPruneTurnPorts ? true : false;
156 nativeConfig->presume_writable_when_fully_relayed =
157 _shouldPresumeWritableWhenFullyRelayed ? true : false;
158 if (_iceCheckMinInterval != nil) {
159 nativeConfig->ice_check_min_interval =
160 rtc::Optional<int>(_iceCheckMinInterval.intValue);
161 }
162
163 return nativeConfig.release();
164 }
165
166 + (webrtc::PeerConnectionInterface::IceTransportsType)
167 nativeTransportsTypeForTransportPolicy:(RTCIceTransportPolicy)policy {
168 switch (policy) {
169 case RTCIceTransportPolicyNone:
170 return webrtc::PeerConnectionInterface::kNone;
171 case RTCIceTransportPolicyRelay:
172 return webrtc::PeerConnectionInterface::kRelay;
173 case RTCIceTransportPolicyNoHost:
174 return webrtc::PeerConnectionInterface::kNoHost;
175 case RTCIceTransportPolicyAll:
176 return webrtc::PeerConnectionInterface::kAll;
177 }
178 }
179
180 + (RTCIceTransportPolicy)transportPolicyForTransportsType:
181 (webrtc::PeerConnectionInterface::IceTransportsType)nativeType {
182 switch (nativeType) {
183 case webrtc::PeerConnectionInterface::kNone:
184 return RTCIceTransportPolicyNone;
185 case webrtc::PeerConnectionInterface::kRelay:
186 return RTCIceTransportPolicyRelay;
187 case webrtc::PeerConnectionInterface::kNoHost:
188 return RTCIceTransportPolicyNoHost;
189 case webrtc::PeerConnectionInterface::kAll:
190 return RTCIceTransportPolicyAll;
191 }
192 }
193
194 + (NSString *)stringForTransportPolicy:(RTCIceTransportPolicy)policy {
195 switch (policy) {
196 case RTCIceTransportPolicyNone:
197 return @"NONE";
198 case RTCIceTransportPolicyRelay:
199 return @"RELAY";
200 case RTCIceTransportPolicyNoHost:
201 return @"NO_HOST";
202 case RTCIceTransportPolicyAll:
203 return @"ALL";
204 }
205 }
206
207 + (webrtc::PeerConnectionInterface::BundlePolicy)nativeBundlePolicyForPolicy:
208 (RTCBundlePolicy)policy {
209 switch (policy) {
210 case RTCBundlePolicyBalanced:
211 return webrtc::PeerConnectionInterface::kBundlePolicyBalanced;
212 case RTCBundlePolicyMaxCompat:
213 return webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat;
214 case RTCBundlePolicyMaxBundle:
215 return webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle;
216 }
217 }
218
219 + (RTCBundlePolicy)bundlePolicyForNativePolicy:
220 (webrtc::PeerConnectionInterface::BundlePolicy)nativePolicy {
221 switch (nativePolicy) {
222 case webrtc::PeerConnectionInterface::kBundlePolicyBalanced:
223 return RTCBundlePolicyBalanced;
224 case webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat:
225 return RTCBundlePolicyMaxCompat;
226 case webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle:
227 return RTCBundlePolicyMaxBundle;
228 }
229 }
230
231 + (NSString *)stringForBundlePolicy:(RTCBundlePolicy)policy {
232 switch (policy) {
233 case RTCBundlePolicyBalanced:
234 return @"BALANCED";
235 case RTCBundlePolicyMaxCompat:
236 return @"MAX_COMPAT";
237 case RTCBundlePolicyMaxBundle:
238 return @"MAX_BUNDLE";
239 }
240 }
241
242 + (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativeRtcpMuxPolicyForPolicy:
243 (RTCRtcpMuxPolicy)policy {
244 switch (policy) {
245 case RTCRtcpMuxPolicyNegotiate:
246 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
247 case RTCRtcpMuxPolicyRequire:
248 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire;
249 }
250 }
251
252 + (RTCRtcpMuxPolicy)rtcpMuxPolicyForNativePolicy:
253 (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativePolicy {
254 switch (nativePolicy) {
255 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate:
256 return RTCRtcpMuxPolicyNegotiate;
257 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire:
258 return RTCRtcpMuxPolicyRequire;
259 }
260 }
261
262 + (NSString *)stringForRtcpMuxPolicy:(RTCRtcpMuxPolicy)policy {
263 switch (policy) {
264 case RTCRtcpMuxPolicyNegotiate:
265 return @"NEGOTIATE";
266 case RTCRtcpMuxPolicyRequire:
267 return @"REQUIRE";
268 }
269 }
270
271 + (webrtc::PeerConnectionInterface::TcpCandidatePolicy)
272 nativeTcpCandidatePolicyForPolicy:(RTCTcpCandidatePolicy)policy {
273 switch (policy) {
274 case RTCTcpCandidatePolicyEnabled:
275 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled;
276 case RTCTcpCandidatePolicyDisabled:
277 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled;
278 }
279 }
280
281 + (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)
282 nativeCandidateNetworkPolicyForPolicy:(RTCCandidateNetworkPolicy)policy {
283 switch (policy) {
284 case RTCCandidateNetworkPolicyAll:
285 return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll;
286 case RTCCandidateNetworkPolicyLowCost:
287 return webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
288 }
289 }
290
291 + (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativePolicy:
292 (webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativePolicy {
293 switch (nativePolicy) {
294 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled:
295 return RTCTcpCandidatePolicyEnabled;
296 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled:
297 return RTCTcpCandidatePolicyDisabled;
298 }
299 }
300
301 + (NSString *)stringForTcpCandidatePolicy:(RTCTcpCandidatePolicy)policy {
302 switch (policy) {
303 case RTCTcpCandidatePolicyEnabled:
304 return @"TCP_ENABLED";
305 case RTCTcpCandidatePolicyDisabled:
306 return @"TCP_DISABLED";
307 }
308 }
309
310 + (RTCCandidateNetworkPolicy)candidateNetworkPolicyForNativePolicy:
311 (webrtc::PeerConnectionInterface::CandidateNetworkPolicy)nativePolicy {
312 switch (nativePolicy) {
313 case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyAll:
314 return RTCCandidateNetworkPolicyAll;
315 case webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost:
316 return RTCCandidateNetworkPolicyLowCost;
317 }
318 }
319
320 + (NSString *)stringForCandidateNetworkPolicy:
321 (RTCCandidateNetworkPolicy)policy {
322 switch (policy) {
323 case RTCCandidateNetworkPolicyAll:
324 return @"CANDIDATE_ALL_NETWORKS";
325 case RTCCandidateNetworkPolicyLowCost:
326 return @"CANDIDATE_LOW_COST_NETWORKS";
327 }
328 }
329
330 + (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)
331 nativeContinualGatheringPolicyForPolicy:
332 (RTCContinualGatheringPolicy)policy {
333 switch (policy) {
334 case RTCContinualGatheringPolicyGatherOnce:
335 return webrtc::PeerConnectionInterface::GATHER_ONCE;
336 case RTCContinualGatheringPolicyGatherContinually:
337 return webrtc::PeerConnectionInterface::GATHER_CONTINUALLY;
338 }
339 }
340
341 + (RTCContinualGatheringPolicy)continualGatheringPolicyForNativePolicy:
342 (webrtc::PeerConnectionInterface::ContinualGatheringPolicy)nativePolicy {
343 switch (nativePolicy) {
344 case webrtc::PeerConnectionInterface::GATHER_ONCE:
345 return RTCContinualGatheringPolicyGatherOnce;
346 case webrtc::PeerConnectionInterface::GATHER_CONTINUALLY:
347 return RTCContinualGatheringPolicyGatherContinually;
348 }
349 }
350
351 + (NSString *)stringForContinualGatheringPolicy:
352 (RTCContinualGatheringPolicy)policy {
353 switch (policy) {
354 case RTCContinualGatheringPolicyGatherOnce:
355 return @"GATHER_ONCE";
356 case RTCContinualGatheringPolicyGatherContinually:
357 return @"GATHER_CONTINUALLY";
358 }
359 }
360
361 + (rtc::KeyType)nativeEncryptionKeyTypeForKeyType:
362 (RTCEncryptionKeyType)keyType {
363 switch (keyType) {
364 case RTCEncryptionKeyTypeRSA:
365 return rtc::KT_RSA;
366 case RTCEncryptionKeyTypeECDSA:
367 return rtc::KT_ECDSA;
368 }
369 }
370
371 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698