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

Side by Side Diff: webrtc/api/objc/RTCConfiguration.mm

Issue 1616303002: Update API for Objective-C RTCConfiguration. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Add some comments Created 4 years, 11 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.h"
12
13 #import "webrtc/api/objc/RTCConfiguration+Private.h"
14 #import "webrtc/api/objc/RTCIceServer+Private.h"
15
16 @implementation RTCConfiguration
17
18 @synthesize iceServers = _iceServers;
19 @synthesize iceTransportPolicy = _iceTransportPolicy;
20 @synthesize bundlePolicy = _bundlePolicy;
21 @synthesize rtcpMuxPolicy = _rtcpMuxPolicy;
22 @synthesize tcpCandidatePolicy = _tcpCandidatePolicy;
23 @synthesize audioJitterBufferMaxPackets = _audioJitterBufferMaxPackets;
24 @synthesize iceConnectionReceivingTimeout = _iceConnectionReceivingTimeout;
25 @synthesize iceBackupCandidatePairPingInterval =
26 _iceBackupCandidatePairPingInterval;
27
28 - (instancetype)init {
29 if (self = [super init]) {
30 // Copy defaults.
31 webrtc::PeerConnectionInterface::RTCConfiguration config;
32 _iceTransportPolicy =
33 [[self class] transportPolicyForTransportsType:config.type];
34 _bundlePolicy =
35 [[self class] bundlePolicyForNativePolicy:config.bundle_policy];
36 _rtcpMuxPolicy =
37 [[self class] rtcpMuxPolicyForNativePolicy:config.rtcp_mux_policy];
38 _tcpCandidatePolicy = [[self class] tcpCandidatePolicyForNativePolicy:
39 config.tcp_candidate_policy];
40 _audioJitterBufferMaxPackets = config.audio_jitter_buffer_max_packets;
41 _iceConnectionReceivingTimeout = config.ice_connection_receiving_timeout;
42 _iceBackupCandidatePairPingInterval =
43 config.ice_backup_candidate_pair_ping_interval;
44 }
45 return self;
46 }
47
48 - (instancetype)initWithIceServers:(NSArray<RTCIceServer *> *)iceServers
49 iceTransportPolicy:(RTCIceTransportPolicy)iceTransportPolicy
50 bundlePolicy:(RTCBundlePolicy)bundlePolicy
51 rtcpMuxPolicy:(RTCRtcpMuxPolicy)rtcpMuxPolicy
52 tcpCandidatePolicy:(RTCTcpCandidatePolicy)tcpCandidatePolicy
53 audioJitterBufferMaxPackets:(int)audioJitterBufferMaxPackets
54 iceConnectionReceivingTimeout:(int)iceConnectionReceivingTimeout
55 iceBackupCandidatePairPingInterval:(int)iceBackupCandidatePairPingInterval {
56 if (self = [self init]) {
57 if (iceServers) {
58 _iceServers = [iceServers copy];
59 }
60 _iceTransportPolicy = iceTransportPolicy;
61 _bundlePolicy = bundlePolicy;
62 _rtcpMuxPolicy = rtcpMuxPolicy;
63 _tcpCandidatePolicy = tcpCandidatePolicy;
64 _audioJitterBufferMaxPackets = audioJitterBufferMaxPackets;
65 _iceConnectionReceivingTimeout = iceConnectionReceivingTimeout;
66 _iceBackupCandidatePairPingInterval = iceBackupCandidatePairPingInterval;
67 }
68 return self;
69 }
70
71 - (NSString *)description {
72 return [NSString stringWithFormat:@"RTCConfiguration:\n%@\n%@\n%@\n%@\n%@\n"
73 "%d\n%d\n%d\n",
74 _iceServers,
75 [[self class] stringForTransportPolicy:
76 _iceTransportPolicy],
77 [[self class] stringForBundlePolicy:
78 _bundlePolicy],
79 [[self class] stringForRtcpMuxPolicy:
80 _rtcpMuxPolicy],
81 [[self class] stringForTcpCandidatePolicy:
82 _tcpCandidatePolicy],
83 _audioJitterBufferMaxPackets,
84 _iceConnectionReceivingTimeout,
85 _iceBackupCandidatePairPingInterval];
86 }
87
88 #pragma mark - Private
89
90 - (webrtc::PeerConnectionInterface::RTCConfiguration)nativeConfiguration {
91 webrtc::PeerConnectionInterface::RTCConfiguration nativeConfig;
92
93 for (RTCIceServer *iceServer in _iceServers) {
94 nativeConfig.servers.push_back(iceServer.iceServer);
95 }
96 nativeConfig.type =
97 [[self class] nativeTransportsTypeForTransportPolicy:_iceTransportPolicy];
98 nativeConfig.bundle_policy =
99 [[self class] nativeBundlePolicyForPolicy:_bundlePolicy];
100 nativeConfig.rtcp_mux_policy =
101 [[self class] nativeRtcpMuxPolicyForPolicy:_rtcpMuxPolicy];
102 nativeConfig.tcp_candidate_policy =
103 [[self class] nativeTcpCandidatePolicyForPolicy:_tcpCandidatePolicy];
104 nativeConfig.audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets;
105 nativeConfig.ice_connection_receiving_timeout =
106 _iceConnectionReceivingTimeout;
107 nativeConfig.ice_backup_candidate_pair_ping_interval =
108 _iceBackupCandidatePairPingInterval;
109
110 return nativeConfig;
111 }
112
113 - (instancetype)initWithNativeConfiguration:
114 (webrtc::PeerConnectionInterface::RTCConfiguration)nativeConfig {
115 NSMutableArray *iceServers =
116 [NSMutableArray arrayWithCapacity:nativeConfig.servers.size()];
117 for (auto const &server : nativeConfig.servers) {
118 RTCIceServer *iceServer =
119 [[RTCIceServer alloc] initWithNativeServer:server];
120 [iceServers addObject:iceServer];
121 }
122
123 if (self = [self init]) {
124 if (iceServers) {
125 _iceServers = [iceServers copy];
126 }
127 _iceTransportPolicy =
128 [[self class] transportPolicyForTransportsType:nativeConfig.type];
129 _bundlePolicy =
130 [[self class] bundlePolicyForNativePolicy:nativeConfig.bundle_policy];
131 _rtcpMuxPolicy = [[self class] rtcpMuxPolicyForNativePolicy:
132 nativeConfig.rtcp_mux_policy];
133 _tcpCandidatePolicy = [[self class] tcpCandidatePolicyForNativePolicy:
134 nativeConfig.tcp_candidate_policy];
135 _audioJitterBufferMaxPackets = nativeConfig.audio_jitter_buffer_max_packets;
136 _iceConnectionReceivingTimeout =
137 nativeConfig.ice_connection_receiving_timeout;
138 _iceBackupCandidatePairPingInterval =
139 nativeConfig.ice_backup_candidate_pair_ping_interval;
140 }
141
142 return self;
143 }
144
145 + (webrtc::PeerConnectionInterface::IceTransportsType)
146 nativeTransportsTypeForTransportPolicy:(RTCIceTransportPolicy)policy {
tkchin_webrtc 2016/01/22 21:17:04 is this because it's called policy in the spec?
hjon_webrtc 2016/01/22 21:35:22 Correct. Added note in the header file calling thi
147 switch (policy) {
148 case RTCIceTransportPolicyNone:
149 return webrtc::PeerConnectionInterface::kNone;
150 case RTCIceTransportPolicyRelay:
151 return webrtc::PeerConnectionInterface::kRelay;
152 case RTCIceTransportPolicyNoHost:
153 return webrtc::PeerConnectionInterface::kNoHost;
154 case RTCIceTransportPolicyAll:
155 return webrtc::PeerConnectionInterface::kAll;
156 }
157 }
158
159 + (RTCIceTransportPolicy)transportPolicyForTransportsType:
160 (webrtc::PeerConnectionInterface::IceTransportsType)nativeType {
161 switch (nativeType) {
162 case webrtc::PeerConnectionInterface::kNone:
163 return RTCIceTransportPolicyNone;
164 case webrtc::PeerConnectionInterface::kRelay:
165 return RTCIceTransportPolicyRelay;
166 case webrtc::PeerConnectionInterface::kNoHost:
167 return RTCIceTransportPolicyNoHost;
168 case webrtc::PeerConnectionInterface::kAll:
169 return RTCIceTransportPolicyAll;
170 }
171 }
172
173 + (NSString *)stringForTransportPolicy:(RTCIceTransportPolicy)policy {
174 switch (policy) {
175 case RTCIceTransportPolicyNone:
176 return @"None";
tkchin_webrtc 2016/01/22 21:17:04 personally I think all these are best all caps e.g
hjon_webrtc 2016/01/22 21:35:22 Done.
177 case RTCIceTransportPolicyRelay:
178 return @"Relay";
179 case RTCIceTransportPolicyNoHost:
180 return @"No host";
181 case RTCIceTransportPolicyAll:
182 return @"All";
183 }
184 }
185
186 + (webrtc::PeerConnectionInterface::BundlePolicy)nativeBundlePolicyForPolicy:
187 (RTCBundlePolicy)policy {
188 switch (policy) {
189 case RTCBundlePolicyBalanced:
190 return webrtc::PeerConnectionInterface::kBundlePolicyBalanced;
191 case RTCBundlePolicyMaxCompat:
192 return webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat;
193 case RTCBundlePolicyMaxBundle:
194 return webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle;
195 }
196 }
197
198 + (RTCBundlePolicy)bundlePolicyForNativePolicy:
199 (webrtc::PeerConnectionInterface::BundlePolicy)nativePolicy {
200 switch (nativePolicy) {
201 case webrtc::PeerConnectionInterface::kBundlePolicyBalanced:
202 return RTCBundlePolicyBalanced;
203 case webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat:
204 return RTCBundlePolicyMaxCompat;
205 case webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle:
206 return RTCBundlePolicyMaxBundle;
207 }
208 }
209
210 + (NSString *)stringForBundlePolicy:(RTCBundlePolicy)policy {
211 switch (policy) {
212 case RTCBundlePolicyBalanced:
213 return @"Balanced";
214 case RTCBundlePolicyMaxCompat:
215 return @"Max compat";
216 case RTCBundlePolicyMaxBundle:
217 return @"Max bundle";
218 }
219 }
220
221 + (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativeRtcpMuxPolicyForPolicy:
222 (RTCRtcpMuxPolicy)policy {
223 switch (policy) {
224 case RTCRtcpMuxPolicyNegotiate:
225 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
226 case RTCRtcpMuxPolicyRequire:
227 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire;
228 }
229 }
230
231 + (RTCRtcpMuxPolicy)rtcpMuxPolicyForNativePolicy:
232 (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativePolicy {
233 switch (nativePolicy) {
234 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate:
235 return RTCRtcpMuxPolicyNegotiate;
236 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire:
237 return RTCRtcpMuxPolicyRequire;
238 }
239 }
240
241 + (NSString *)stringForRtcpMuxPolicy:(RTCRtcpMuxPolicy)policy {
242 switch (policy) {
243 case RTCRtcpMuxPolicyNegotiate:
244 return @"Negotiate";
245 case RTCRtcpMuxPolicyRequire:
246 return @"Require";
247 }
248 }
249
250 + (webrtc::PeerConnectionInterface::TcpCandidatePolicy)
251 nativeTcpCandidatePolicyForPolicy:(RTCTcpCandidatePolicy)policy {
252 switch (policy) {
253 case RTCTcpCandidatePolicyEnabled:
254 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled;
255 case RTCTcpCandidatePolicyDisabled:
256 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled;
257 }
258 }
259
260 + (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativePolicy:
261 (webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativePolicy {
262 switch (nativePolicy) {
263 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled:
264 return RTCTcpCandidatePolicyEnabled;
265 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled:
266 return RTCTcpCandidatePolicyDisabled;
267 }
268 }
269
270 + (NSString *)stringForTcpCandidatePolicy:(RTCTcpCandidatePolicy)policy {
271 switch (policy) {
272 case RTCTcpCandidatePolicyEnabled:
273 return @"Enabled";
274 case RTCTcpCandidatePolicyDisabled:
275 return @"Disabled";
276 }
277 }
278
279 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698