Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1334)

Unified Diff: webrtc/api/objc/RTCSessionDescription.mm

Issue 1524303006: Update API for Objective-C RTCSessionDescription. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@updateRTCIceCandidate
Patch Set: Updates based on feedback Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/api/objc/RTCSessionDescription.h ('k') | webrtc/api/objc/RTCSessionDescription+Private.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/api/objc/RTCSessionDescription.mm
diff --git a/webrtc/api/objc/RTCSessionDescription.mm b/webrtc/api/objc/RTCSessionDescription.mm
new file mode 100644
index 0000000000000000000000000000000000000000..6b93b8262fa240e19c4326f52e5501074488fce3
--- /dev/null
+++ b/webrtc/api/objc/RTCSessionDescription.mm
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2015 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#import "RTCSessionDescription.h"
+
+#import "webrtc/api/objc/RTCSessionDescription+Private.h"
+#import "webrtc/base/objc/NSString+StdString.h"
+#import "webrtc/base/objc/RTCLogging.h"
+
+@implementation RTCSessionDescription
+
+@synthesize type = _type;
+@synthesize sdp = _sdp;
+
+- (instancetype)initWithType:(RTCSdpType)type sdp:(NSString *)sdp {
+ NSParameterAssert(sdp.length);
+ if (self = [super init]) {
+ _type = type;
+ _sdp = [sdp copy];
+ }
+ return self;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"RTCSessionDescription:\n%@\n%@",
+ [[self class] stringForType:_type],
+ _sdp];
+}
+
+#pragma mark - Private
+
+- (webrtc::SessionDescriptionInterface *)nativeDescription {
+ webrtc::SdpParseError error;
+
+ NSString *typeString = [[self class] stringForType:_type];
+ webrtc::SessionDescriptionInterface *description =
+ webrtc::CreateSessionDescription(typeString.stdString,
+ _sdp.stdString,
+ &error);
+
+ if (!description) {
+ RTCLog(@"Failed to create session description: %s\nline: %s",
+ error.description.c_str(),
+ error.line.c_str());
+ }
+
+ return description;
+}
+
+- (instancetype)initWithNativeDescription:
+ (webrtc::SessionDescriptionInterface *)description {
+ NSParameterAssert(description);
+ std::string sdp;
+ description->ToString(&sdp);
+ NSString *typeString = [NSString stringForStdString:description->type()];
+
+ return [self initWithType:[[self class] typeForString:typeString]
+ sdp:[NSString stringForStdString:sdp]];
+}
+
++ (NSString *)stringForType:(RTCSdpType)type {
+ switch (type) {
+ case RTCSdpTypeOffer:
+ return @"offer";
+ case RTCSdpTypePrAnswer:
+ return @"pranswer";
+ case RTCSdpTypeAnswer:
+ return @"answer";
+ }
+}
+
++ (RTCSdpType)typeForString:(NSString *)string {
+ NSParameterAssert(string.length);
+ if ([string isEqualToString:@"offer"]) {
+ return RTCSdpTypeOffer;
+ } else if ([string isEqualToString:@"pranswer"]) {
+ return RTCSdpTypePrAnswer;
+ } else if ([string isEqualToString:@"answer"]) {
+ return RTCSdpTypeAnswer;
+ } else {
+ 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
+ }
+}
+
+@end
« no previous file with comments | « webrtc/api/objc/RTCSessionDescription.h ('k') | webrtc/api/objc/RTCSessionDescription+Private.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698