From f48d3cfbabbd9c94c358dd78f461cb01a0253d8a Mon Sep 17 00:00:00 2001 From: Mirko Bonadei Date: Sat, 31 Jul 2021 09:53:25 +0000 Subject: [PATCH] Revert "An RTCSessionDescription will now return nil from its initializer if the SDP passed to it is invalid." This reverts commit 48cd9dbc5067f266b07541d2eebfb4b88fe455d4. Reason for revert: Breaks downstream project. Original change's description: > An RTCSessionDescription will now return nil from its initializer if the SDP passed to it is invalid. > > Bug: webrtc:13022 > Change-Id: I2f2ad96884cf2f43f5ea95c1210470dd6aa5c919 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/226980 > Commit-Queue: Jake Bromberg > Reviewed-by: Harald Alvestrand > Cr-Commit-Position: refs/heads/master@{#34607} TBR=peah@webrtc.org,hta@webrtc.org,webrtc-scoped@luci-project-accounts.iam.gserviceaccount.com,jakebromberg@google.com Change-Id: Iee05f747e472208f8776944df15d9206485b167e No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: webrtc:13022 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/227341 Reviewed-by: Mirko Bonadei Commit-Queue: Mirko Bonadei Cr-Commit-Position: refs/heads/master@{#34615} --- .../peerconnection/RTCSessionDescription.h | 6 +-- .../peerconnection/RTCSessionDescription.mm | 45 +++++++++---------- .../unittests/RTCSessionDescriptionTest.mm | 14 ------ 3 files changed, 22 insertions(+), 43 deletions(-) diff --git a/sdk/objc/api/peerconnection/RTCSessionDescription.h b/sdk/objc/api/peerconnection/RTCSessionDescription.h index 0ef60cc38d..8a9479d5cf 100644 --- a/sdk/objc/api/peerconnection/RTCSessionDescription.h +++ b/sdk/objc/api/peerconnection/RTCSessionDescription.h @@ -36,10 +36,8 @@ RTC_OBJC_EXPORT - (instancetype)init NS_UNAVAILABLE; -/** Initialize a session description with a type and SDP string. Returns nil if the sdp is invalid. - */ -- (nullable instancetype)initWithType:(RTCSdpType)type - sdp:(NSString *)sdp NS_DESIGNATED_INITIALIZER; +/** Initialize a session description with a type and SDP string. */ +- (instancetype)initWithType:(RTCSdpType)type sdp:(NSString *)sdp NS_DESIGNATED_INITIALIZER; + (NSString *)stringForType:(RTCSdpType)type; diff --git a/sdk/objc/api/peerconnection/RTCSessionDescription.mm b/sdk/objc/api/peerconnection/RTCSessionDescription.mm index 3e235b1985..9fd97fee23 100644 --- a/sdk/objc/api/peerconnection/RTCSessionDescription.mm +++ b/sdk/objc/api/peerconnection/RTCSessionDescription.mm @@ -17,45 +17,23 @@ @implementation RTC_OBJC_TYPE (RTCSessionDescription) -@synthesize nativeDescription = _nativeDescription; @synthesize type = _type; @synthesize sdp = _sdp; + (NSString *)stringForType:(RTCSdpType)type { - std::string string = [self stdStringForType:type]; + std::string string = [[self class] stdStringForType:type]; return [NSString stringForStdString:string]; } + (RTCSdpType)typeForString:(NSString *)string { std::string typeString = string.stdString; - return [self typeForStdString:typeString]; + return [[self class] typeForStdString:typeString]; } -+ (webrtc::SessionDescriptionInterface *)nativeDescriptionForString:(NSString *)sdp - type:(RTCSdpType)type { - webrtc::SdpParseError error; - - webrtc::SessionDescriptionInterface *description = - webrtc::CreateSessionDescription([self stdStringForType:type], sdp.stdString, &error); - - if (!description) { - RTCLogError(@"Failed to create session description: %s\nline: %s", - error.description.c_str(), - error.line.c_str()); - } - - return description; -} - -- (nullable instancetype)initWithType:(RTCSdpType)type sdp:(NSString *)sdp { +- (instancetype)initWithType:(RTCSdpType)type sdp:(NSString *)sdp { if (self = [super init]) { _type = type; _sdp = [sdp copy]; - _nativeDescription = [[self class] nativeDescriptionForString:_sdp type:_type]; - - if (_nativeDescription == nil) { - return nil; - } } return self; } @@ -68,6 +46,23 @@ #pragma mark - Private +- (webrtc::SessionDescriptionInterface *)nativeDescription { + webrtc::SdpParseError error; + + webrtc::SessionDescriptionInterface *description = + webrtc::CreateSessionDescription([[self class] stdStringForType:_type], + _sdp.stdString, + &error); + + if (!description) { + RTCLogError(@"Failed to create session description: %s\nline: %s", + error.description.c_str(), + error.line.c_str()); + } + + return description; +} + - (instancetype)initWithNativeDescription: (const webrtc::SessionDescriptionInterface *)nativeDescription { NSParameterAssert(nativeDescription); diff --git a/sdk/objc/unittests/RTCSessionDescriptionTest.mm b/sdk/objc/unittests/RTCSessionDescriptionTest.mm index 1f8a75d16f..ee65649cbc 100644 --- a/sdk/objc/unittests/RTCSessionDescriptionTest.mm +++ b/sdk/objc/unittests/RTCSessionDescriptionTest.mm @@ -42,13 +42,6 @@ EXPECT_EQ([self sdp].stdString, sdp); } -- (void)testInvalidSessionDescriptionConversion { - RTC_OBJC_TYPE(RTCSessionDescription) *description = - [[RTC_OBJC_TYPE(RTCSessionDescription) alloc] initWithType:RTCSdpTypeAnswer sdp:@"invalid"]; - - EXPECT_EQ(nil, description); -} - - (void)testInitFromNativeSessionDescription { webrtc::SessionDescriptionInterface *nativeDescription; @@ -142,13 +135,6 @@ TEST(RTCSessionDescriptionTest, SessionDescriptionConversionTest) { } } -TEST(RTCSessionDescriptionTest, InvalidSessionDescriptionConversionTest) { - @autoreleasepool { - RTCSessionDescriptionTest *test = [[RTCSessionDescriptionTest alloc] init]; - [test testInvalidSessionDescriptionConversion]; - } -} - TEST(RTCSessionDescriptionTest, InitFromSessionDescriptionTest) { @autoreleasepool { RTCSessionDescriptionTest *test = [[RTCSessionDescriptionTest alloc] init];