Chromium Code Reviews| 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 #import "webrtc/api/objc/RTCSessionDescription+Private.h" | |
| 14 #import "webrtc/base/objc/NSString+StdString.h" | |
| 15 #import "webrtc/base/objc/RTCLogging.h" | |
| 16 | |
| 17 @implementation RTCSessionDescription | |
| 18 | |
| 19 @synthesize type = _type; | |
| 20 @synthesize sdp = _sdp; | |
| 21 | |
| 22 - (instancetype)initWithType:(RTCSdpType)type sdp:(NSString *)sdp { | |
| 23 NSParameterAssert(sdp.length); | |
| 24 if (self = [super init]) { | |
| 25 _type = type; | |
| 26 _sdp = [sdp copy]; | |
| 27 } | |
| 28 return self; | |
| 29 } | |
| 30 | |
| 31 - (NSString *)description { | |
| 32 return [NSString stringWithFormat:@"RTCSessionDescription:\n%@\n%@", | |
| 33 [[self class] stringForType:_type], | |
| 34 _sdp]; | |
| 35 } | |
| 36 | |
| 37 #pragma mark - Private | |
| 38 | |
| 39 - (webrtc::SessionDescriptionInterface *)nativeDescription { | |
| 40 webrtc::SdpParseError error; | |
| 41 | |
| 42 NSString *typeString = [[self class] stringForType:_type]; | |
| 43 webrtc::SessionDescriptionInterface *description = | |
| 44 webrtc::CreateSessionDescription(typeString.stdString, | |
| 45 _sdp.stdString, | |
| 46 &error); | |
| 47 | |
| 48 if (!description) { | |
| 49 RTCLog(@"Failed to create session description: %s\nline: %s", | |
| 50 error.description.c_str(), | |
| 51 error.line.c_str()); | |
| 52 } | |
| 53 | |
| 54 return description; | |
| 55 } | |
| 56 | |
| 57 - (instancetype)initWithNativeDescription: | |
| 58 (webrtc::SessionDescriptionInterface *)description { | |
| 59 NSParameterAssert(description); | |
| 60 std::string sdp; | |
| 61 description->ToString(&sdp); | |
| 62 NSString *typeString = [NSString stringForStdString:description->type()]; | |
| 63 | |
| 64 return [self initWithType:[[self class] typeForString:typeString] | |
| 65 sdp:[NSString stringForStdString:sdp]]; | |
| 66 } | |
| 67 | |
| 68 + (NSString *)stringForType:(RTCSdpType)type { | |
| 69 switch (type) { | |
| 70 case RTCSdpTypeOffer: | |
| 71 return @"offer"; | |
| 72 case RTCSdpTypePrAnswer: | |
| 73 return @"pranswer"; | |
| 74 case RTCSdpTypeAnswer: | |
| 75 return @"answer"; | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 + (RTCSdpType)typeForString:(NSString *)string { | |
| 80 NSParameterAssert(string.length); | |
| 81 if ([string isEqualToString:@"offer"]) { | |
| 82 return RTCSdpTypeOffer; | |
| 83 } else if ([string isEqualToString:@"pranswer"]) { | |
| 84 return RTCSdpTypePrAnswer; | |
| 85 } else if ([string isEqualToString:@"answer"]) { | |
| 86 return RTCSdpTypeAnswer; | |
| 87 } else { | |
| 88 NSAssert(false, @"|string| is not a known SDP type."); | |
|
hjon
2016/01/05 22:16:20
tkchin@ What do you think about this method? Conce
| |
| 89 } | |
| 90 } | |
| 91 | |
| 92 @end | |
| OLD | NEW |