Zeke Chin | bc7dd7e | 2015-05-29 14:59:14 -0700 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
| 3 | * Copyright 2015 Google Inc. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright notice, |
| 9 | * this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #import "talk/app/webrtc/objc/RTCPeerConnectionInterface+Internal.h" |
| 29 | |
| 30 | #import "talk/app/webrtc/objc/RTCEnumConverter.h" |
| 31 | #import "talk/app/webrtc/objc/RTCICEServer+Internal.h" |
| 32 | |
| 33 | @implementation RTCConfiguration |
| 34 | |
| 35 | @synthesize iceTransportsType = _iceTransportsType; |
| 36 | @synthesize iceServers = _iceServers; |
| 37 | @synthesize bundlePolicy = _bundlePolicy; |
| 38 | @synthesize rtcpMuxPolicy = _rtcpMuxPolicy; |
| 39 | @synthesize tcpCandidatePolicy = _tcpCandidatePolicy; |
| 40 | @synthesize audioJitterBufferMaxPackets = _audioJitterBufferMaxPackets; |
honghaiz | 4edc39c | 2015-09-01 09:53:56 -0700 | [diff] [blame^] | 41 | @synthesize iceConnectionReceivingTimeout = _iceConnectionReceivingTimeout; |
Zeke Chin | bc7dd7e | 2015-05-29 14:59:14 -0700 | [diff] [blame] | 42 | |
| 43 | - (instancetype)init { |
| 44 | if (self = [super init]) { |
| 45 | // Copy defaults. |
| 46 | webrtc::PeerConnectionInterface::RTCConfiguration config; |
| 47 | _iceTransportsType = [RTCEnumConverter iceTransportsTypeForNativeEnum:config.type]; |
| 48 | _bundlePolicy = [RTCEnumConverter bundlePolicyForNativeEnum:config.bundle_policy]; |
| 49 | _rtcpMuxPolicy = [RTCEnumConverter rtcpMuxPolicyForNativeEnum:config.rtcp_mux_policy]; |
| 50 | _tcpCandidatePolicy = |
| 51 | [RTCEnumConverter tcpCandidatePolicyForNativeEnum:config.tcp_candidate_policy]; |
| 52 | _audioJitterBufferMaxPackets = config.audio_jitter_buffer_max_packets; |
honghaiz | 4edc39c | 2015-09-01 09:53:56 -0700 | [diff] [blame^] | 53 | _iceConnectionReceivingTimeout = config.ice_connection_receiving_timeout; |
Zeke Chin | bc7dd7e | 2015-05-29 14:59:14 -0700 | [diff] [blame] | 54 | } |
| 55 | return self; |
| 56 | } |
| 57 | |
| 58 | - (instancetype)initWithIceTransportsType:(RTCIceTransportsType)iceTransportsType |
| 59 | bundlePolicy:(RTCBundlePolicy)bundlePolicy |
| 60 | rtcpMuxPolicy:(RTCRtcpMuxPolicy)rtcpMuxPolicy |
| 61 | tcpCandidatePolicy:(RTCTcpCandidatePolicy)tcpCandidatePolicy |
honghaiz | 4edc39c | 2015-09-01 09:53:56 -0700 | [diff] [blame^] | 62 | audioJitterBufferMaxPackets:(int)audioJitterBufferMaxPackets |
| 63 | iceConnectionReceivingTimeout:(int)iceConnectionReceivingTimeout { |
Zeke Chin | bc7dd7e | 2015-05-29 14:59:14 -0700 | [diff] [blame] | 64 | if (self = [super init]) { |
| 65 | _iceTransportsType = iceTransportsType; |
| 66 | _bundlePolicy = bundlePolicy; |
| 67 | _rtcpMuxPolicy = rtcpMuxPolicy; |
| 68 | _tcpCandidatePolicy = tcpCandidatePolicy; |
| 69 | _audioJitterBufferMaxPackets = audioJitterBufferMaxPackets; |
honghaiz | 4edc39c | 2015-09-01 09:53:56 -0700 | [diff] [blame^] | 70 | _iceConnectionReceivingTimeout = iceConnectionReceivingTimeout; |
Zeke Chin | bc7dd7e | 2015-05-29 14:59:14 -0700 | [diff] [blame] | 71 | } |
| 72 | return self; |
| 73 | } |
| 74 | |
| 75 | #pragma mark - Private |
| 76 | |
| 77 | - (webrtc::PeerConnectionInterface::RTCConfiguration)nativeConfiguration { |
| 78 | webrtc::PeerConnectionInterface::RTCConfiguration nativeConfig; |
| 79 | nativeConfig.type = [RTCEnumConverter nativeEnumForIceTransportsType:_iceTransportsType]; |
| 80 | for (RTCICEServer *iceServer : _iceServers) { |
| 81 | nativeConfig.servers.push_back(iceServer.iceServer); |
| 82 | } |
| 83 | nativeConfig.bundle_policy = [RTCEnumConverter nativeEnumForBundlePolicy:_bundlePolicy]; |
| 84 | nativeConfig.rtcp_mux_policy = [RTCEnumConverter nativeEnumForRtcpMuxPolicy:_rtcpMuxPolicy]; |
| 85 | nativeConfig.tcp_candidate_policy = |
| 86 | [RTCEnumConverter nativeEnumForTcpCandidatePolicy:_tcpCandidatePolicy]; |
| 87 | nativeConfig.audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets; |
honghaiz | 4edc39c | 2015-09-01 09:53:56 -0700 | [diff] [blame^] | 88 | nativeConfig.ice_connection_receiving_timeout = |
| 89 | _iceConnectionReceivingTimeout; |
Zeke Chin | bc7dd7e | 2015-05-29 14:59:14 -0700 | [diff] [blame] | 90 | return nativeConfig; |
| 91 | } |
| 92 | |
| 93 | @end |