blob: 7b1e65568b487da0e3b515c99cc60e2dd143acdb [file] [log] [blame]
Jon Hjelle29d5e572016-01-06 11:49:11 -08001/*
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
tkchin9eeb6242016-04-27 01:54:20 -070011#import "RTCIceCandidate+Private.h"
Jon Hjelle29d5e572016-01-06 11:49:11 -080012
tkchin9eeb6242016-04-27 01:54:20 -070013#import "NSString+StdString.h"
14#import "WebRTC/RTCLogging.h"
Jon Hjelle29d5e572016-01-06 11:49:11 -080015
16@implementation RTCIceCandidate
17
18@synthesize sdpMid = _sdpMid;
19@synthesize sdpMLineIndex = _sdpMLineIndex;
20@synthesize sdp = _sdp;
21
22- (instancetype)initWithSdp:(NSString *)sdp
tkchin121ac122016-03-21 09:08:40 -070023 sdpMLineIndex:(int)sdpMLineIndex
Jon Hjelle29d5e572016-01-06 11:49:11 -080024 sdpMid:(NSString *)sdpMid {
25 NSParameterAssert(sdp.length);
26 if (self = [super init]) {
27 _sdpMid = [sdpMid copy];
28 _sdpMLineIndex = sdpMLineIndex;
29 _sdp = [sdp copy];
30 }
31 return self;
32}
33
34- (NSString *)description {
tkchin121ac122016-03-21 09:08:40 -070035 return [NSString stringWithFormat:@"RTCIceCandidate:\n%@\n%d\n%@",
Jon Hjelle29d5e572016-01-06 11:49:11 -080036 _sdpMid,
tkchin121ac122016-03-21 09:08:40 -070037 _sdpMLineIndex,
Jon Hjelle29d5e572016-01-06 11:49:11 -080038 _sdp];
39}
40
41#pragma mark - Private
42
43- (instancetype)initWithNativeCandidate:
hjonf396f602016-02-11 16:19:06 -080044 (const webrtc::IceCandidateInterface *)candidate {
Jon Hjelle29d5e572016-01-06 11:49:11 -080045 NSParameterAssert(candidate);
46 std::string sdp;
47 candidate->ToString(&sdp);
48
49 return [self initWithSdp:[NSString stringForStdString:sdp]
50 sdpMLineIndex:candidate->sdp_mline_index()
51 sdpMid:[NSString stringForStdString:candidate->sdp_mid()]];
52}
53
54- (rtc::scoped_ptr<webrtc::IceCandidateInterface>)nativeCandidate {
55 webrtc::SdpParseError error;
56
57 webrtc::IceCandidateInterface *candidate = webrtc::CreateIceCandidate(
58 _sdpMid.stdString, _sdpMLineIndex, _sdp.stdString, &error);
59
60 if (!candidate) {
61 RTCLog(@"Failed to create ICE candidate: %s\nline: %s",
62 error.description.c_str(),
63 error.line.c_str());
64 }
65
66 return rtc::scoped_ptr<webrtc::IceCandidateInterface>(candidate);
67}
68
69@end