Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions sdk/objc/api/peerconnection/RTCPeerConnection.mm
Original file line number Diff line number Diff line change
Expand Up @@ -437,20 +437,18 @@ - (void)addIceCandidate:(RTC_OBJC_TYPE(RTCIceCandidate) *)candidate {
- (void)addIceCandidate:(RTC_OBJC_TYPE(RTCIceCandidate) *)candidate
completionHandler:(void (^)(NSError *_Nullable error))completionHandler {
RTC_DCHECK(completionHandler != nil);
auto iceCandidate = webrtc::CreateIceCandidate(candidate.nativeCandidate->sdp_mid(),
candidate.nativeCandidate->sdp_mline_index(),
candidate.nativeCandidate->candidate());
_peerConnection->AddIceCandidate(std::move(iceCandidate), [completionHandler](const auto &error) {
if (error.ok()) {
completionHandler(nil);
} else {
NSString *str = [NSString stringForStdString:error.message()];
NSError *err = [NSError errorWithDomain:kRTCPeerConnectionErrorDomain
code:static_cast<NSInteger>(error.type())
userInfo:@{NSLocalizedDescriptionKey : str}];
completionHandler(err);
}
});
_peerConnection->AddIceCandidate(
candidate.nativeCandidate, [completionHandler](const auto &error) {
if (error.ok()) {
completionHandler(nil);
} else {
NSString *str = [NSString stringForStdString:error.message()];
NSError *err = [NSError errorWithDomain:kRTCPeerConnectionErrorDomain
code:static_cast<NSInteger>(error.type())
userInfo:@{NSLocalizedDescriptionKey : str}];
completionHandler(err);
}
});
}
- (void)removeIceCandidates:(NSArray<RTC_OBJC_TYPE(RTCIceCandidate) *> *)iceCandidates {
std::vector<cricket::Candidate> candidates;
Expand Down Expand Up @@ -581,7 +579,7 @@ - (void)setLocalDescription:(RTC_OBJC_TYPE(RTCSessionDescription) *)sdp
RTC_DCHECK(completionHandler != nil);
rtc::scoped_refptr<webrtc::SetLocalDescriptionObserverInterface> observer(
new rtc::RefCountedObject<::SetSessionDescriptionObserver>(completionHandler));
_peerConnection->SetLocalDescription(sdp.nativeDescription->Clone(), observer);
_peerConnection->SetLocalDescription(sdp.nativeDescription, observer);
Comment on lines -584 to +582
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clone()은 뭔가요? Copying인가요?
제거하신 이유가 뭔가요?

}

- (void)setLocalDescriptionWithCompletionHandler:
Expand All @@ -597,7 +595,7 @@ - (void)setRemoteDescription:(RTC_OBJC_TYPE(RTCSessionDescription) *)sdp
RTC_DCHECK(completionHandler != nil);
rtc::scoped_refptr<webrtc::SetRemoteDescriptionObserverInterface> observer(
new rtc::RefCountedObject<::SetSessionDescriptionObserver>(completionHandler));
_peerConnection->SetRemoteDescription(sdp.nativeDescription->Clone(), observer);
_peerConnection->SetRemoteDescription(sdp.nativeDescription, observer);
}

- (BOOL)setBweMinBitrateBps:(nullable NSNumber *)minBitrateBps
Expand Down
3 changes: 2 additions & 1 deletion sdk/objc/api/peerconnection/RTCSessionDescription+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ NS_ASSUME_NONNULL_BEGIN
* RTCSessionDescription object. This is needed to pass to the underlying C++
* APIs.
*/
@property(nonatomic, readonly, nullable) webrtc::SessionDescriptionInterface *nativeDescription;
@property(nonatomic,
readonly) std::unique_ptr<webrtc::SessionDescriptionInterface> nativeDescription;

/**
* Initialize an RTCSessionDescription from a native
Expand Down
8 changes: 3 additions & 5 deletions sdk/objc/api/peerconnection/RTCSessionDescription.mm
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,11 @@ - (NSString *)description {

#pragma mark - Private

- (webrtc::SessionDescriptionInterface *)nativeDescription {
- (std::unique_ptr<webrtc::SessionDescriptionInterface>)nativeDescription {
webrtc::SdpParseError error;

webrtc::SessionDescriptionInterface *description =
webrtc::CreateSessionDescription([[self class] stdStringForType:_type],
_sdp.stdString,
&error);
std::unique_ptr<webrtc::SessionDescriptionInterface> description(webrtc::CreateSessionDescription(
[[self class] stdStringForType:_type], _sdp.stdString, &error));

if (!description) {
RTCLogError(@"Failed to create session description: %s\nline: %s",
Expand Down
78 changes: 78 additions & 0 deletions sdk/objc/unittests/RTCPeerConnectionTest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@
#import "api/peerconnection/RTCConfiguration+Private.h"
#import "api/peerconnection/RTCConfiguration.h"
#import "api/peerconnection/RTCCryptoOptions.h"
#import "api/peerconnection/RTCIceCandidate.h"
#import "api/peerconnection/RTCIceServer.h"
#import "api/peerconnection/RTCMediaConstraints.h"
#import "api/peerconnection/RTCPeerConnection.h"
#import "api/peerconnection/RTCPeerConnectionFactory+Native.h"
#import "api/peerconnection/RTCPeerConnectionFactory.h"
#import "api/peerconnection/RTCSessionDescription.h"
#import "helpers/NSString+StdString.h"

@interface RTCPeerConnectionTest : NSObject
- (void)testConfigurationGetter;
- (void)testWithDependencies;
- (void)testWithInvalidSDP;
- (void)testWithInvalidIceCandidate;
@end

@implementation RTCPeerConnectionTest
Expand Down Expand Up @@ -137,6 +141,66 @@ - (void)testWithDependencies {
}
}

- (void)testWithInvalidSDP {
RTC_OBJC_TYPE(RTCPeerConnectionFactory) *factory =
[[RTC_OBJC_TYPE(RTCPeerConnectionFactory) alloc] init];

RTC_OBJC_TYPE(RTCConfiguration) *config = [[RTC_OBJC_TYPE(RTCConfiguration) alloc] init];
RTC_OBJC_TYPE(RTCMediaConstraints) *contraints =
[[RTC_OBJC_TYPE(RTCMediaConstraints) alloc] initWithMandatoryConstraints:@{}
optionalConstraints:nil];
RTC_OBJC_TYPE(RTCPeerConnection) *peerConnection =
[factory peerConnectionWithConfiguration:config constraints:contraints delegate:nil];

dispatch_semaphore_t negotiatedSem = dispatch_semaphore_create(0);
[peerConnection setRemoteDescription:[[RTC_OBJC_TYPE(RTCSessionDescription) alloc]
initWithType:RTCSdpTypeOffer
sdp:@"invalid"]
completionHandler:^(NSError *error) {
ASSERT_NE(error, nil);
if (error != nil) {
dispatch_semaphore_signal(negotiatedSem);
}
}];

NSTimeInterval timeout = 5;
ASSERT_EQ(
0,
dispatch_semaphore_wait(negotiatedSem,
dispatch_time(DISPATCH_TIME_NOW, (int64_t)(timeout * NSEC_PER_SEC))));
Comment on lines +162 to +170
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

167 번째줄의 ASSERT_EQ은 162번째줄의 disaptch_semaphor_signal 메소드 호출까지 기다리는게 맞나요?

[peerConnection close];
}

- (void)testWithInvalidIceCandidate {
RTC_OBJC_TYPE(RTCPeerConnectionFactory) *factory =
[[RTC_OBJC_TYPE(RTCPeerConnectionFactory) alloc] init];

RTC_OBJC_TYPE(RTCConfiguration) *config = [[RTC_OBJC_TYPE(RTCConfiguration) alloc] init];
RTC_OBJC_TYPE(RTCMediaConstraints) *contraints =
[[RTC_OBJC_TYPE(RTCMediaConstraints) alloc] initWithMandatoryConstraints:@{}
optionalConstraints:nil];
RTC_OBJC_TYPE(RTCPeerConnection) *peerConnection =
[factory peerConnectionWithConfiguration:config constraints:contraints delegate:nil];

dispatch_semaphore_t negotiatedSem = dispatch_semaphore_create(0);
[peerConnection addIceCandidate:[[RTC_OBJC_TYPE(RTCIceCandidate) alloc] initWithSdp:@"invalid"
sdpMLineIndex:-1
sdpMid:nil]
completionHandler:^(NSError *error) {
ASSERT_NE(error, nil);
if (error != nil) {
dispatch_semaphore_signal(negotiatedSem);
}
}];

NSTimeInterval timeout = 5;
ASSERT_EQ(
0,
dispatch_semaphore_wait(negotiatedSem,
dispatch_time(DISPATCH_TIME_NOW, (int64_t)(timeout * NSEC_PER_SEC))));
[peerConnection close];
}

@end

TEST(RTCPeerConnectionTest, ConfigurationGetterTest) {
Expand All @@ -152,3 +216,17 @@ - (void)testWithDependencies {
[test testWithDependencies];
}
}

TEST(RTCPeerConnectionTest, TestWithInvalidSDP) {
@autoreleasepool {
RTCPeerConnectionTest *test = [[RTCPeerConnectionTest alloc] init];
[test testWithInvalidSDP];
}
}

TEST(RTCPeerConnectionTest, TestWithInvalidIceCandidate) {
@autoreleasepool {
RTCPeerConnectionTest *test = [[RTCPeerConnectionTest alloc] init];
[test testWithInvalidIceCandidate];
}
}
2 changes: 1 addition & 1 deletion sdk/objc/unittests/RTCSessionDescriptionTest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ - (void)testSessionDescriptionConversion {
RTC_OBJC_TYPE(RTCSessionDescription) *description =
[[RTC_OBJC_TYPE(RTCSessionDescription) alloc] initWithType:RTCSdpTypeAnswer sdp:[self sdp]];

webrtc::SessionDescriptionInterface *nativeDescription =
std::unique_ptr<webrtc::SessionDescriptionInterface> nativeDescription =
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

둘의 차이가 뭔가요?

description.nativeDescription;

EXPECT_EQ(RTCSdpTypeAnswer,
Expand Down