OLD | NEW |
| (Empty) |
1 /* | |
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 | |
11 #import "RTCSessionDescription.h" | |
12 | |
13 #include "webrtc/base/checks.h" | |
14 | |
15 #import "webrtc/api/objc/RTCSessionDescription+Private.h" | |
16 #import "webrtc/base/objc/NSString+StdString.h" | |
17 #import "webrtc/base/objc/RTCLogging.h" | |
18 | |
19 @implementation RTCSessionDescription | |
20 | |
21 @synthesize type = _type; | |
22 @synthesize sdp = _sdp; | |
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 | |
34 - (instancetype)initWithType:(RTCSdpType)type sdp:(NSString *)sdp { | |
35 NSParameterAssert(sdp.length); | |
36 if (self = [super init]) { | |
37 _type = type; | |
38 _sdp = [sdp copy]; | |
39 } | |
40 return self; | |
41 } | |
42 | |
43 - (NSString *)description { | |
44 return [NSString stringWithFormat:@"RTCSessionDescription:\n%@\n%@", | |
45 [[self class] stringForType:_type], | |
46 _sdp]; | |
47 } | |
48 | |
49 #pragma mark - Private | |
50 | |
51 - (webrtc::SessionDescriptionInterface *)nativeDescription { | |
52 webrtc::SdpParseError error; | |
53 | |
54 webrtc::SessionDescriptionInterface *description = | |
55 webrtc::CreateSessionDescription([[self class] stdStringForType:_type], | |
56 _sdp.stdString, | |
57 &error); | |
58 | |
59 if (!description) { | |
60 RTCLogError(@"Failed to create session description: %s\nline: %s", | |
61 error.description.c_str(), | |
62 error.line.c_str()); | |
63 } | |
64 | |
65 return description; | |
66 } | |
67 | |
68 - (instancetype)initWithNativeDescription: | |
69 (const webrtc::SessionDescriptionInterface *)nativeDescription { | |
70 NSParameterAssert(nativeDescription); | |
71 std::string sdp; | |
72 nativeDescription->ToString(&sdp); | |
73 RTCSdpType type = [[self class] typeForStdString:nativeDescription->type()]; | |
74 | |
75 return [self initWithType:type | |
76 sdp:[NSString stringForStdString:sdp]]; | |
77 } | |
78 | |
79 + (std::string)stdStringForType:(RTCSdpType)type { | |
80 switch (type) { | |
81 case RTCSdpTypeOffer: | |
82 return webrtc::SessionDescriptionInterface::kOffer; | |
83 case RTCSdpTypePrAnswer: | |
84 return webrtc::SessionDescriptionInterface::kPrAnswer; | |
85 case RTCSdpTypeAnswer: | |
86 return webrtc::SessionDescriptionInterface::kAnswer; | |
87 } | |
88 } | |
89 | |
90 + (RTCSdpType)typeForStdString:(const std::string &)string { | |
91 if (string == webrtc::SessionDescriptionInterface::kOffer) { | |
92 return RTCSdpTypeOffer; | |
93 } else if (string == webrtc::SessionDescriptionInterface::kPrAnswer) { | |
94 return RTCSdpTypePrAnswer; | |
95 } else if (string == webrtc::SessionDescriptionInterface::kAnswer) { | |
96 return RTCSdpTypeAnswer; | |
97 } else { | |
98 RTC_NOTREACHED(); | |
99 return RTCSdpTypeOffer; | |
100 } | |
101 } | |
102 | |
103 @end | |
OLD | NEW |