1/* 2 * libjingle 3 * Copyright 2013 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 "RTCEnumConverter.h" 29 30#include "talk/app/webrtc/peerconnectioninterface.h" 31 32@implementation RTCEnumConverter 33 34+ (RTCICEConnectionState)convertIceConnectionStateToObjC: 35 (webrtc::PeerConnectionInterface::IceConnectionState)nativeState { 36 switch (nativeState) { 37 case webrtc::PeerConnectionInterface::kIceConnectionNew: 38 return RTCICEConnectionNew; 39 case webrtc::PeerConnectionInterface::kIceConnectionChecking: 40 return RTCICEConnectionChecking; 41 case webrtc::PeerConnectionInterface::kIceConnectionConnected: 42 return RTCICEConnectionConnected; 43 case webrtc::PeerConnectionInterface::kIceConnectionCompleted: 44 return RTCICEConnectionCompleted; 45 case webrtc::PeerConnectionInterface::kIceConnectionFailed: 46 return RTCICEConnectionFailed; 47 case webrtc::PeerConnectionInterface::kIceConnectionDisconnected: 48 return RTCICEConnectionDisconnected; 49 case webrtc::PeerConnectionInterface::kIceConnectionClosed: 50 return RTCICEConnectionClosed; 51 case webrtc::PeerConnectionInterface::kIceConnectionMax: 52 NSAssert(NO, @"kIceConnectionMax not allowed"); 53 return RTCICEConnectionMax; 54 } 55} 56 57+ (RTCICEGatheringState)convertIceGatheringStateToObjC: 58 (webrtc::PeerConnectionInterface::IceGatheringState)nativeState { 59 switch (nativeState) { 60 case webrtc::PeerConnectionInterface::kIceGatheringNew: 61 return RTCICEGatheringNew; 62 case webrtc::PeerConnectionInterface::kIceGatheringGathering: 63 return RTCICEGatheringGathering; 64 case webrtc::PeerConnectionInterface::kIceGatheringComplete: 65 return RTCICEGatheringComplete; 66 } 67} 68 69+ (RTCSignalingState)convertSignalingStateToObjC: 70 (webrtc::PeerConnectionInterface::SignalingState)nativeState { 71 switch (nativeState) { 72 case webrtc::PeerConnectionInterface::kStable: 73 return RTCSignalingStable; 74 case webrtc::PeerConnectionInterface::kHaveLocalOffer: 75 return RTCSignalingHaveLocalOffer; 76 case webrtc::PeerConnectionInterface::kHaveLocalPrAnswer: 77 return RTCSignalingHaveLocalPrAnswer; 78 case webrtc::PeerConnectionInterface::kHaveRemoteOffer: 79 return RTCSignalingHaveRemoteOffer; 80 case webrtc::PeerConnectionInterface::kHaveRemotePrAnswer: 81 return RTCSignalingHaveRemotePrAnswer; 82 case webrtc::PeerConnectionInterface::kClosed: 83 return RTCSignalingClosed; 84 } 85} 86 87+ (webrtc::PeerConnectionInterface::StatsOutputLevel) 88 convertStatsOutputLevelToNative:(RTCStatsOutputLevel)statsOutputLevel { 89 switch (statsOutputLevel) { 90 case RTCStatsOutputLevelStandard: 91 return webrtc::PeerConnectionInterface::kStatsOutputLevelStandard; 92 case RTCStatsOutputLevelDebug: 93 return webrtc::PeerConnectionInterface::kStatsOutputLevelDebug; 94 } 95} 96 97+ (RTCSourceState)convertSourceStateToObjC: 98 (webrtc::MediaSourceInterface::SourceState)nativeState { 99 switch (nativeState) { 100 case webrtc::MediaSourceInterface::kInitializing: 101 return RTCSourceStateInitializing; 102 case webrtc::MediaSourceInterface::kLive: 103 return RTCSourceStateLive; 104 case webrtc::MediaSourceInterface::kEnded: 105 return RTCSourceStateEnded; 106 case webrtc::MediaSourceInterface::kMuted: 107 return RTCSourceStateMuted; 108 } 109} 110 111+ (webrtc::MediaStreamTrackInterface::TrackState) 112 convertTrackStateToNative:(RTCTrackState)state { 113 switch (state) { 114 case RTCTrackStateInitializing: 115 return webrtc::MediaStreamTrackInterface::kInitializing; 116 case RTCTrackStateLive: 117 return webrtc::MediaStreamTrackInterface::kLive; 118 case RTCTrackStateEnded: 119 return webrtc::MediaStreamTrackInterface::kEnded; 120 case RTCTrackStateFailed: 121 return webrtc::MediaStreamTrackInterface::kFailed; 122 } 123} 124 125+ (RTCTrackState)convertTrackStateToObjC: 126 (webrtc::MediaStreamTrackInterface::TrackState)nativeState { 127 switch (nativeState) { 128 case webrtc::MediaStreamTrackInterface::kInitializing: 129 return RTCTrackStateInitializing; 130 case webrtc::MediaStreamTrackInterface::kLive: 131 return RTCTrackStateLive; 132 case webrtc::MediaStreamTrackInterface::kEnded: 133 return RTCTrackStateEnded; 134 case webrtc::MediaStreamTrackInterface::kFailed: 135 return RTCTrackStateFailed; 136 } 137} 138 139+ (RTCIceTransportsType)iceTransportsTypeForNativeEnum: 140 (webrtc::PeerConnectionInterface::IceTransportsType)nativeEnum { 141 switch (nativeEnum) { 142 case webrtc::PeerConnectionInterface::kNone: 143 return kRTCIceTransportsTypeNone; 144 case webrtc::PeerConnectionInterface::kRelay: 145 return kRTCIceTransportsTypeRelay; 146 case webrtc::PeerConnectionInterface::kNoHost: 147 return kRTCIceTransportsTypeNoHost; 148 case webrtc::PeerConnectionInterface::kAll: 149 return kRTCIceTransportsTypeAll; 150 } 151} 152 153+ (webrtc::PeerConnectionInterface::IceTransportsType)nativeEnumForIceTransportsType: 154 (RTCIceTransportsType)iceTransportsType { 155 switch (iceTransportsType) { 156 case kRTCIceTransportsTypeNone: 157 return webrtc::PeerConnectionInterface::kNone; 158 case kRTCIceTransportsTypeRelay: 159 return webrtc::PeerConnectionInterface::kRelay; 160 case kRTCIceTransportsTypeNoHost: 161 return webrtc::PeerConnectionInterface::kNoHost; 162 case kRTCIceTransportsTypeAll: 163 return webrtc::PeerConnectionInterface::kAll; 164 } 165} 166 167+ (RTCBundlePolicy)bundlePolicyForNativeEnum: 168 (webrtc::PeerConnectionInterface::BundlePolicy)nativeEnum { 169 switch (nativeEnum) { 170 case webrtc::PeerConnectionInterface::kBundlePolicyBalanced: 171 return kRTCBundlePolicyBalanced; 172 case webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle: 173 return kRTCBundlePolicyMaxBundle; 174 case webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat: 175 return kRTCBundlePolicyMaxCompat; 176 } 177} 178 179+ (webrtc::PeerConnectionInterface::BundlePolicy)nativeEnumForBundlePolicy: 180 (RTCBundlePolicy)bundlePolicy { 181 switch (bundlePolicy) { 182 case kRTCBundlePolicyBalanced: 183 return webrtc::PeerConnectionInterface::kBundlePolicyBalanced; 184 case kRTCBundlePolicyMaxBundle: 185 return webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle; 186 case kRTCBundlePolicyMaxCompat: 187 return webrtc::PeerConnectionInterface::kBundlePolicyMaxCompat; 188 } 189} 190 191+ (RTCRtcpMuxPolicy)rtcpMuxPolicyForNativeEnum: 192 (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativeEnum { 193 switch (nativeEnum) { 194 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate: 195 return kRTCRtcpMuxPolicyNegotiate; 196 case webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire: 197 return kRTCRtcpMuxPolicyRequire; 198 } 199} 200 201+ (webrtc::PeerConnectionInterface::RtcpMuxPolicy)nativeEnumForRtcpMuxPolicy: 202 (RTCRtcpMuxPolicy)rtcpMuxPolicy { 203 switch (rtcpMuxPolicy) { 204 case kRTCRtcpMuxPolicyNegotiate: 205 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate; 206 case kRTCRtcpMuxPolicyRequire: 207 return webrtc::PeerConnectionInterface::kRtcpMuxPolicyRequire; 208 } 209} 210 211+ (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativeEnum: 212 (webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativeEnum { 213 switch (nativeEnum) { 214 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled: 215 return kRTCTcpCandidatePolicyEnabled; 216 case webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled: 217 return kRTCTcpCandidatePolicyDisabled; 218 } 219} 220 221+ (webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativeEnumForTcpCandidatePolicy: 222 (RTCTcpCandidatePolicy)tcpCandidatePolicy { 223 switch (tcpCandidatePolicy) { 224 case kRTCTcpCandidatePolicyEnabled: 225 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyEnabled; 226 case kRTCTcpCandidatePolicyDisabled: 227 return webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled; 228 } 229} 230 231@end 232