Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 _iceServers = [NSMutableArray array]; | |
| 31 // Copy defaults. | |
| 32 webrtc::PeerConnectionInterface::RTCConfiguration config; | |
| 33 _iceTransportPolicy = | |
| 34 [[self class] transportPolicyForTransportsType:config.type]; | |
| 35 _bundlePolicy = | |
| 36 [[self class] bundlePolicyForNativePolicy:config.bundle_policy]; | |
| 37 _rtcpMuxPolicy = | |
| 38 [[self class] rtcpMuxPolicyForNativePolicy:config.rtcp_mux_policy]; | |
| 39 _tcpCandidatePolicy = [[self class] tcpCandidatePolicyForNativePolicy: | |
| 40 config.tcp_candidate_policy]; | |
| 41 _audioJitterBufferMaxPackets = config.audio_jitter_buffer_max_packets; | |
| 42 _iceConnectionReceivingTimeout = config.ice_connection_receiving_timeout; | |
| 43 _iceBackupCandidatePairPingInterval = | |
| 44 config.ice_backup_candidate_pair_ping_interval; | |
| 45 } | |
| 46 return self; | |
| 47 } | |
| 48 | |
| 49 - (instancetype)initWithIceServers:(NSArray<RTCIceServer *> *)iceServers | |
| 50 iceTransportPolicy:(RTCIceTransportPolicy)iceTransportPolicy | |
| 51 bundlePolicy:(RTCBundlePolicy)bundlePolicy | |
| 52 rtcpMuxPolicy:(RTCRtcpMuxPolicy)rtcpMuxPolicy | |
| 53 tcpCandidatePolicy:(RTCTcpCandidatePolicy)tcpCandidatePolicy | |
| 54 audioJitterBufferMaxPackets:(int)audioJitterBufferMaxPackets | |
| 55 iceConnectionReceivingTimeout:(int)iceConnectionReceivingTimeout | |
| 56 iceBackupCandidatePairPingInterval:(int)iceBackupCandidatePairPingInterval { | |
| 57 if (self = [self init]) { | |
| 58 if (iceServers) { | |
| 59 _iceServers = [iceServers copy]; | |
| 60 } | |
| 61 _iceTransportPolicy = iceTransportPolicy; | |
| 62 _bundlePolicy = bundlePolicy; | |
| 63 _rtcpMuxPolicy = rtcpMuxPolicy; | |
| 64 _tcpCandidatePolicy = tcpCandidatePolicy; | |
| 65 _audioJitterBufferMaxPackets = audioJitterBufferMaxPackets; | |
| 66 _iceConnectionReceivingTimeout = iceConnectionReceivingTimeout; | |
| 67 _iceBackupCandidatePairPingInterval = iceBackupCandidatePairPingInterval; | |
| 68 } | |
| 69 return self; | |
| 70 } | |
| 71 | |
| 72 - (NSString *)description { | |
| 73 return [NSString stringWithFormat: | |
| 74 @"RTCConfiguration: {\n%@\n%@\n%@\n%@\n%@\n%d\n%d\n%d\n}\n", | |
|
tkchin_webrtc
2016/01/22 22:49:56
indent 4 not 2
hjon_webrtc
2016/01/25 19:25:03
Done.
| |
| 75 _iceServers, | |
| 76 [[self class] stringForTransportPolicy:_iceTransportPolicy], | |
| 77 [[self class] stringForBundlePolicy:_bundlePolicy], | |
| 78 [[self class] stringForRtcpMuxPolicy:_rtcpMuxPolicy], | |
| 79 [[self class] stringForTcpCandidatePolicy:_tcpCandidatePolicy], | |
| 80 _audioJitterBufferMaxPackets, | |
| 81 _iceConnectionReceivingTimeout, | |
| 82 _iceBackupCandidatePairPingInterval]; | |
| 83 } | |
| 84 | |
| 85 #pragma mark - Private | |
| 86 | |
| 87 - (webrtc::PeerConnectionInterface::RTCConfiguration)nativeConfiguration { | |
| 88 webrtc::PeerConnectionInterface::RTCConfiguration nativeConfig; | |
| 89 | |
| 90 for (RTCIceServer *iceServer in _iceServers) { | |
| 91 nativeConfig.servers.push_back(iceServer.iceServer); | |
| 92 } | |
| 93 nativeConfig.type = | |
| 94 [[self class] nativeTransportsTypeForTransportPolicy:_iceTransportPolicy]; | |
| 95 nativeConfig.bundle_policy = | |
| 96 [[self class] nativeBundlePolicyForPolicy:_bundlePolicy]; | |
| 97 nativeConfig.rtcp_mux_policy = | |
| 98 [[self class] nativeRtcpMuxPolicyForPolicy:_rtcpMuxPolicy]; | |
| 99 nativeConfig.tcp_candidate_policy = | |
| 100 [[self class] nativeTcpCandidatePolicyForPolicy:_tcpCandidatePolicy]; | |
| 101 nativeConfig.audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets; | |
| 102 nativeConfig.ice_connection_receiving_timeout = | |
| 103 _iceConnectionReceivingTimeout; | |
| 104 nativeConfig.ice_backup_candidate_pair_ping_interval = | |
| 105 _iceBackupCandidatePairPingInterval; | |
| 106 | |
| 107 return nativeConfig; | |
| 108 } | |
| 109 | |
| 110 - (instancetype)initWithNativeConfiguration: | |
| 111 (webrtc::PeerConnectionInterface::RTCConfiguration)nativeConfig { | |
| 112 NSMutableArray *iceServers = | |
| 113 [NSMutableArray arrayWithCapacity:nativeConfig.servers.size()]; | |
| 114 for (auto const &server : nativeConfig.servers) { | |
| 115 RTCIceServer *iceServer = | |
| 116 [[RTCIceServer alloc] initWithNativeServer:server]; | |
| 117 [iceServers addObject:iceServer]; | |
| 118 } | |
| 119 | |
| 120 if (self = [self init]) { | |
| 121 if (iceServers) { | |
| 122 _iceServers = [iceServers copy]; | |
| 123 } | |
| 124 _iceTransportPolicy = | |
| 125 [[self class] transportPolicyForTransportsType:nativeConfig.type]; | |
| 126 _bundlePolicy = | |
| 127 [[self class] bundlePolicyForNativePolicy:nativeConfig.bundle_policy]; | |
| 128 _rtcpMuxPolicy = [[self class] rtcpMuxPolicyForNativePolicy: | |
| 129 nativeConfig.rtcp_mux_policy]; | |
| 130 _tcpCandidatePolicy = [[self class] tcpCandidatePolicyForNativePolicy: | |
| 131 nativeConfig.tcp_candidate_policy]; | |
| 132 _audioJitterBufferMaxPackets = nativeConfig.audio_jitter_buffer_max_packets; | |
| 133 _iceConnectionReceivingTimeout = | |
| 134 nativeConfig.ice_connection_receiving_timeout; | |
| 135 _iceBackupCandidatePairPingInterval = | |
| 136 nativeConfig.ice_backup_candidate_pair_ping_interval; | |
| 137 } | |
| 138 | |
| 139 return self; | |
| 140 } | |
| 141 | |
| 142 + (webrtc::PeerConnectionInterface::IceTransportsType) | |
| 143 nativeTransportsTypeForTransportPolicy:(RTCIceTransportPolicy)policy { | |
| 144 switch (policy) { | |
| 145 case RTCIceTransportPolicyNone: | |
| 146 return webrtc::PeerConnectionInterface::kNone; | |
| 147 case RTCIceTransportPolicyRelay: | |
| 148 return webrtc::PeerConnectionInterface::kRelay; | |
| 149 case RTCIceTransportPolicyNoHost: | |
| 150 return webrtc::PeerConnectionInterface::kNoHost; | |
| 151 case RTCIceTransportPolicyAll: | |
| 152 return webrtc::PeerConnectionInterface::kAll; | |
| 153 } | |
| 154 } | |
| 155 | |
| 156 + (RTCIceTransportPolicy)transportPolicyForTransportsType: | |
| 157 (webrtc::PeerConnectionInterface::IceTransportsType)nativeType { | |
| 158 switch (nativeType) { | |
| 159 case webrtc::PeerConnectionInterface::kNone: | |
| 160 return RTCIceTransportPolicyNone; | |
| 161 case webrtc::PeerConnectionInterface::kRelay: | |
| 162 return RTCIceTransportPolicyRelay; | |
| 163 case webrtc::PeerConnectionInterface::kNoHost: | |
| 164 return RTCIceTransportPolicyNoHost; | |
| 165 case webrtc::PeerConnectionInterface::kAll: | |
| 166 return RTCIceTransportPolicyAll; | |
| 167 } | |
| 168 } | |
| 169 | |
| 170 + (NSString *)stringForTransportPolicy:(RTCIceTransportPolicy)policy { | |
| 171 switch (policy) { | |
| 172 case RTCIceTransportPolicyNone: | |
| 173 return @"NONE"; | |
| 174 case RTCIceTransportPolicyRelay: | |
| 175 return @"RELAY"; | |
| 176 case RTCIceTransportPolicyNoHost: | |
| 177 return @"NO_HOST"; | |
| 178 case RTCIceTransportPolicyAll: | |
| 179 return @"ALL"; | |
| 180 } | |
| 181 } | |
| 182 | |
| 183 + (webrtc::PeerConnectionInterface::BundlePolicy)nativeBundlePolicyForPolicy: | |
| 184 (RTCBundlePolicy)policy { | |
| 185 switch (policy) { | |
| 186 case RTCBundlePolicyBalanced: | |
| 187 return webrtc::PeerConnectionInterface::kBundlePolicyBalanced; | |
| 188 case RTCBundlePolicyMaxCompat: | |
| 189 return webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat; | |
| 190 case RTCBundlePolicyMaxBundle: | |
| 191 return webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle; | |
| 192 } | |
| 193 } | |
| 194 | |
| 195 + (RTCBundlePolicy)bundlePolicyForNativePolicy: | |
| 196 (webrtc::PeerConnectionInterface::BundlePolicy)nativePolicy { | |
| 197 switch (nativePolicy) { | |
| 198 case webrtc::PeerConnectionInterface::kBundlePolicyBalanced: | |
| 199 return RTCBundlePolicyBalanced; | |
| 200 case webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat: | |
| 201 return RTCBundlePolicyMaxCompat; | |
| 202 case webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle: | |
| 203 return RTCBundlePolicyMaxBundle; | |
| 204 } | |
| 205 } | |
| 206 | |
| 207 + (NSString *)stringForBundlePolicy:(RTCBundlePolicy)policy { | |
| 208 switch (policy) { | |
| 209 case RTCBundlePolicyBalanced: | |
| 210 return @"BALANCED"; | |
| 211 case RTCBundlePolicyMaxCompat: | |
| 212 return @"MAX_COMPAT"; | |
| 213 case RTCBundlePolicyMaxBundle: | |
| 214 return @"MAX_BUNDLE"; | |
| 215 } | |
| 216 } | |
| 217 | |
| 218 + (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativeRtcpMuxPolicyForPolicy: | |
| 219 (RTCRtcpMuxPolicy)policy { | |
| 220 switch (policy) { | |
| 221 case RTCRtcpMuxPolicyNegotiate: | |
| 222 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate; | |
| 223 case RTCRtcpMuxPolicyRequire: | |
| 224 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire; | |
| 225 } | |
| 226 } | |
| 227 | |
| 228 + (RTCRtcpMuxPolicy)rtcpMuxPolicyForNativePolicy: | |
| 229 (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativePolicy { | |
| 230 switch (nativePolicy) { | |
| 231 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate: | |
| 232 return RTCRtcpMuxPolicyNegotiate; | |
| 233 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire: | |
| 234 return RTCRtcpMuxPolicyRequire; | |
| 235 } | |
| 236 } | |
| 237 | |
| 238 + (NSString *)stringForRtcpMuxPolicy:(RTCRtcpMuxPolicy)policy { | |
| 239 switch (policy) { | |
| 240 case RTCRtcpMuxPolicyNegotiate: | |
| 241 return @"NEGOTIATE"; | |
| 242 case RTCRtcpMuxPolicyRequire: | |
| 243 return @"REQUIRE"; | |
| 244 } | |
| 245 } | |
| 246 | |
| 247 + (webrtc::PeerConnectionInterface::TcpCandidatePolicy) | |
| 248 nativeTcpCandidatePolicyForPolicy:(RTCTcpCandidatePolicy)policy { | |
| 249 switch (policy) { | |
| 250 case RTCTcpCandidatePolicyEnabled: | |
| 251 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled; | |
| 252 case RTCTcpCandidatePolicyDisabled: | |
| 253 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled; | |
| 254 } | |
| 255 } | |
| 256 | |
| 257 + (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativePolicy: | |
| 258 (webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativePolicy { | |
| 259 switch (nativePolicy) { | |
| 260 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled: | |
| 261 return RTCTcpCandidatePolicyEnabled; | |
| 262 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled: | |
| 263 return RTCTcpCandidatePolicyDisabled; | |
| 264 } | |
| 265 } | |
| 266 | |
| 267 + (NSString *)stringForTcpCandidatePolicy:(RTCTcpCandidatePolicy)policy { | |
| 268 switch (policy) { | |
| 269 case RTCTcpCandidatePolicyEnabled: | |
| 270 return @"ENABLED"; | |
|
tkchin_webrtc
2016/01/22 22:49:56
suggest TCP_ENABLED/DISABLED
hjon_webrtc
2016/01/25 19:25:03
Done.
| |
| 271 case RTCTcpCandidatePolicyDisabled: | |
| 272 return @"DISABLED"; | |
| 273 } | |
| 274 } | |
| 275 | |
| 276 @end | |
| OLD | NEW |