OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #import "RTCSessionDescription.h" | 11 #import "RTCSessionDescription.h" |
12 | 12 |
13 #include "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
14 | 14 |
15 #import "webrtc/api/objc/RTCSessionDescription+Private.h" | 15 #import "webrtc/api/objc/RTCSessionDescription+Private.h" |
16 #import "webrtc/base/objc/NSString+StdString.h" | 16 #import "webrtc/base/objc/NSString+StdString.h" |
17 #import "webrtc/base/objc/RTCLogging.h" | 17 #import "webrtc/base/objc/RTCLogging.h" |
18 | 18 |
19 @implementation RTCSessionDescription | 19 @implementation RTCSessionDescription |
20 | 20 |
21 @synthesize type = _type; | 21 @synthesize type = _type; |
22 @synthesize sdp = _sdp; | 22 @synthesize sdp = _sdp; |
23 | 23 |
| 24 + (NSString *)stringForType:(RTCSdpType)type { |
| 25 std::string string = [[self class] stdStringForType:type]; |
| 26 return [NSString stringForStdString:string]; |
| 27 } |
| 28 |
| 29 + (RTCSdpType)typeForString:(NSString *)string { |
| 30 std::string typeString = string.stdString; |
| 31 return [[self class] typeForStdString:typeString]; |
| 32 } |
| 33 |
24 - (instancetype)initWithType:(RTCSdpType)type sdp:(NSString *)sdp { | 34 - (instancetype)initWithType:(RTCSdpType)type sdp:(NSString *)sdp { |
25 NSParameterAssert(sdp.length); | 35 NSParameterAssert(sdp.length); |
26 if (self = [super init]) { | 36 if (self = [super init]) { |
27 _type = type; | 37 _type = type; |
28 _sdp = [sdp copy]; | 38 _sdp = [sdp copy]; |
29 } | 39 } |
30 return self; | 40 return self; |
31 } | 41 } |
32 | 42 |
33 - (NSString *)description { | 43 - (NSString *)description { |
34 return [NSString stringWithFormat:@"RTCSessionDescription:\n%s\n%@", | 44 return [NSString stringWithFormat:@"RTCSessionDescription:\n%@\n%@", |
35 [[self class] stringForType:_type].c_str(), | 45 [[self class] stringForType:_type], |
36 _sdp]; | 46 _sdp]; |
37 } | 47 } |
38 | 48 |
39 #pragma mark - Private | 49 #pragma mark - Private |
40 | 50 |
41 - (webrtc::SessionDescriptionInterface *)nativeDescription { | 51 - (webrtc::SessionDescriptionInterface *)nativeDescription { |
42 webrtc::SdpParseError error; | 52 webrtc::SdpParseError error; |
43 | 53 |
44 webrtc::SessionDescriptionInterface *description = | 54 webrtc::SessionDescriptionInterface *description = |
45 webrtc::CreateSessionDescription([[self class] stringForType:_type], | 55 webrtc::CreateSessionDescription([[self class] stdStringForType:_type], |
46 _sdp.stdString, | 56 _sdp.stdString, |
47 &error); | 57 &error); |
48 | 58 |
49 if (!description) { | 59 if (!description) { |
50 RTCLogError(@"Failed to create session description: %s\nline: %s", | 60 RTCLogError(@"Failed to create session description: %s\nline: %s", |
51 error.description.c_str(), | 61 error.description.c_str(), |
52 error.line.c_str()); | 62 error.line.c_str()); |
53 } | 63 } |
54 | 64 |
55 return description; | 65 return description; |
56 } | 66 } |
57 | 67 |
58 - (instancetype)initWithNativeDescription: | 68 - (instancetype)initWithNativeDescription: |
59 (const webrtc::SessionDescriptionInterface *)nativeDescription { | 69 (const webrtc::SessionDescriptionInterface *)nativeDescription { |
60 NSParameterAssert(nativeDescription); | 70 NSParameterAssert(nativeDescription); |
61 std::string sdp; | 71 std::string sdp; |
62 nativeDescription->ToString(&sdp); | 72 nativeDescription->ToString(&sdp); |
63 RTCSdpType type = [[self class] typeForString:nativeDescription->type()]; | 73 RTCSdpType type = [[self class] typeForStdString:nativeDescription->type()]; |
64 | 74 |
65 return [self initWithType:type | 75 return [self initWithType:type |
66 sdp:[NSString stringForStdString:sdp]]; | 76 sdp:[NSString stringForStdString:sdp]]; |
67 } | 77 } |
68 | 78 |
69 + (std::string)stringForType:(RTCSdpType)type { | 79 + (std::string)stdStringForType:(RTCSdpType)type { |
70 switch (type) { | 80 switch (type) { |
71 case RTCSdpTypeOffer: | 81 case RTCSdpTypeOffer: |
72 return webrtc::SessionDescriptionInterface::kOffer; | 82 return webrtc::SessionDescriptionInterface::kOffer; |
73 case RTCSdpTypePrAnswer: | 83 case RTCSdpTypePrAnswer: |
74 return webrtc::SessionDescriptionInterface::kPrAnswer; | 84 return webrtc::SessionDescriptionInterface::kPrAnswer; |
75 case RTCSdpTypeAnswer: | 85 case RTCSdpTypeAnswer: |
76 return webrtc::SessionDescriptionInterface::kAnswer; | 86 return webrtc::SessionDescriptionInterface::kAnswer; |
77 } | 87 } |
78 } | 88 } |
79 | 89 |
80 + (RTCSdpType)typeForString:(const std::string &)string { | 90 + (RTCSdpType)typeForStdString:(const std::string &)string { |
81 if (string == webrtc::SessionDescriptionInterface::kOffer) { | 91 if (string == webrtc::SessionDescriptionInterface::kOffer) { |
82 return RTCSdpTypeOffer; | 92 return RTCSdpTypeOffer; |
83 } else if (string == webrtc::SessionDescriptionInterface::kPrAnswer) { | 93 } else if (string == webrtc::SessionDescriptionInterface::kPrAnswer) { |
84 return RTCSdpTypePrAnswer; | 94 return RTCSdpTypePrAnswer; |
85 } else if (string == webrtc::SessionDescriptionInterface::kAnswer) { | 95 } else if (string == webrtc::SessionDescriptionInterface::kAnswer) { |
86 return RTCSdpTypeAnswer; | 96 return RTCSdpTypeAnswer; |
87 } else { | 97 } else { |
88 RTC_NOTREACHED(); | 98 RTC_NOTREACHED(); |
89 return RTCSdpTypeOffer; | 99 return RTCSdpTypeOffer; |
90 } | 100 } |
91 } | 101 } |
92 | 102 |
93 @end | 103 @end |
OLD | NEW |