blob: 193403d11d8fcfd8157100c426128b64bb30e3f0 [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
kwibergbfefb032016-05-01 14:53:46 -070013#include <memory>
14
tkchin9eeb6242016-04-27 01:54:20 -070015#import "NSString+StdString.h"
16#import "WebRTC/RTCLogging.h"
Jon Hjelle29d5e572016-01-06 11:49:11 -080017
18@implementation RTCIceCandidate
19
20@synthesize sdpMid = _sdpMid;
21@synthesize sdpMLineIndex = _sdpMLineIndex;
22@synthesize sdp = _sdp;
23
24- (instancetype)initWithSdp:(NSString *)sdp
tkchin121ac122016-03-21 09:08:40 -070025 sdpMLineIndex:(int)sdpMLineIndex
Jon Hjelle29d5e572016-01-06 11:49:11 -080026 sdpMid:(NSString *)sdpMid {
27 NSParameterAssert(sdp.length);
28 if (self = [super init]) {
29 _sdpMid = [sdpMid copy];
30 _sdpMLineIndex = sdpMLineIndex;
31 _sdp = [sdp copy];
32 }
33 return self;
34}
35
36- (NSString *)description {
tkchin121ac122016-03-21 09:08:40 -070037 return [NSString stringWithFormat:@"RTCIceCandidate:\n%@\n%d\n%@",
Jon Hjelle29d5e572016-01-06 11:49:11 -080038 _sdpMid,
tkchin121ac122016-03-21 09:08:40 -070039 _sdpMLineIndex,
Jon Hjelle29d5e572016-01-06 11:49:11 -080040 _sdp];
41}
42
43#pragma mark - Private
44
45- (instancetype)initWithNativeCandidate:
hjonf396f602016-02-11 16:19:06 -080046 (const webrtc::IceCandidateInterface *)candidate {
Jon Hjelle29d5e572016-01-06 11:49:11 -080047 NSParameterAssert(candidate);
48 std::string sdp;
49 candidate->ToString(&sdp);
50
51 return [self initWithSdp:[NSString stringForStdString:sdp]
52 sdpMLineIndex:candidate->sdp_mline_index()
53 sdpMid:[NSString stringForStdString:candidate->sdp_mid()]];
54}
55
kwibergbfefb032016-05-01 14:53:46 -070056- (std::unique_ptr<webrtc::IceCandidateInterface>)nativeCandidate {
Jon Hjelle29d5e572016-01-06 11:49:11 -080057 webrtc::SdpParseError error;
58
59 webrtc::IceCandidateInterface *candidate = webrtc::CreateIceCandidate(
60 _sdpMid.stdString, _sdpMLineIndex, _sdp.stdString, &error);
61
62 if (!candidate) {
63 RTCLog(@"Failed to create ICE candidate: %s\nline: %s",
64 error.description.c_str(),
65 error.line.c_str());
66 }
67
kwibergbfefb032016-05-01 14:53:46 -070068 return std::unique_ptr<webrtc::IceCandidateInterface>(candidate);
Jon Hjelle29d5e572016-01-06 11:49:11 -080069}
70
71@end