Fixed crash when PCF is destroyed before RTCRtpTranceiver in ObjC
Bug: webrtc:9231 Change-Id: Icecc319eaf6edd2c4b7b05fda984660412cb0d40 Reviewed-on: https://webrtc-review.googlesource.com/87439 Reviewed-by: Kári Helgason <kthelgason@webrtc.org> Commit-Queue: Kári Helgason <kthelgason@webrtc.org> Cr-Commit-Position: refs/heads/master@{#23884}
This commit is contained in:

committed by
Commit Bot

parent
42a2fc9cba
commit
08f14dd388
@ -151,9 +151,10 @@ void PeerConnectionDelegateAdapter::OnRemoveStream(
|
|||||||
|
|
||||||
void PeerConnectionDelegateAdapter::OnTrack(
|
void PeerConnectionDelegateAdapter::OnTrack(
|
||||||
rtc::scoped_refptr<RtpTransceiverInterface> nativeTransceiver) {
|
rtc::scoped_refptr<RtpTransceiverInterface> nativeTransceiver) {
|
||||||
RTCRtpTransceiver *transceiver =
|
|
||||||
[[RTCRtpTransceiver alloc] initWithNativeRtpTransceiver:nativeTransceiver];
|
|
||||||
RTCPeerConnection *peer_connection = peer_connection_;
|
RTCPeerConnection *peer_connection = peer_connection_;
|
||||||
|
RTCRtpTransceiver *transceiver =
|
||||||
|
[[RTCRtpTransceiver alloc] initWithFactory:peer_connection.factory
|
||||||
|
nativeRtpTransceiver:nativeTransceiver];
|
||||||
if ([peer_connection.delegate
|
if ([peer_connection.delegate
|
||||||
respondsToSelector:@selector(peerConnection:didStartReceivingOnTransceiver:)]) {
|
respondsToSelector:@selector(peerConnection:didStartReceivingOnTransceiver:)]) {
|
||||||
[peer_connection.delegate peerConnection:peer_connection
|
[peer_connection.delegate peerConnection:peer_connection
|
||||||
@ -409,8 +410,8 @@ void PeerConnectionDelegateAdapter::OnAddTrack(
|
|||||||
@"Failed to add transceiver %@: %s", track, nativeTransceiverOrError.error().message());
|
@"Failed to add transceiver %@: %s", track, nativeTransceiverOrError.error().message());
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
return
|
return [[RTCRtpTransceiver alloc] initWithFactory:self.factory
|
||||||
[[RTCRtpTransceiver alloc] initWithNativeRtpTransceiver:nativeTransceiverOrError.MoveValue()];
|
nativeRtpTransceiver:nativeTransceiverOrError.MoveValue()];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (RTCRtpTransceiver *)addTransceiverOfType:(RTCRtpMediaType)mediaType {
|
- (RTCRtpTransceiver *)addTransceiverOfType:(RTCRtpMediaType)mediaType {
|
||||||
@ -428,8 +429,8 @@ void PeerConnectionDelegateAdapter::OnAddTrack(
|
|||||||
nativeTransceiverOrError.error().message());
|
nativeTransceiverOrError.error().message());
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
return
|
return [[RTCRtpTransceiver alloc] initWithFactory:self.factory
|
||||||
[[RTCRtpTransceiver alloc] initWithNativeRtpTransceiver:nativeTransceiverOrError.MoveValue()];
|
nativeRtpTransceiver:nativeTransceiverOrError.MoveValue()];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)offerForConstraints:(RTCMediaConstraints *)constraints
|
- (void)offerForConstraints:(RTCMediaConstraints *)constraints
|
||||||
@ -554,8 +555,8 @@ void PeerConnectionDelegateAdapter::OnAddTrack(
|
|||||||
_peerConnection->GetTransceivers());
|
_peerConnection->GetTransceivers());
|
||||||
NSMutableArray *transceivers = [[NSMutableArray alloc] init];
|
NSMutableArray *transceivers = [[NSMutableArray alloc] init];
|
||||||
for (auto nativeTransceiver : nativeTransceivers) {
|
for (auto nativeTransceiver : nativeTransceivers) {
|
||||||
RTCRtpTransceiver *transceiver =
|
RTCRtpTransceiver *transceiver = [[RTCRtpTransceiver alloc] initWithFactory:self.factory
|
||||||
[[RTCRtpTransceiver alloc] initWithNativeRtpTransceiver:nativeTransceiver];
|
nativeRtpTransceiver:nativeTransceiver];
|
||||||
[transceivers addObject:transceiver];
|
[transceivers addObject:transceiver];
|
||||||
}
|
}
|
||||||
return transceivers;
|
return transceivers;
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
@class RTCPeerConnectionFactory;
|
||||||
|
|
||||||
@interface RTCRtpTransceiverInit ()
|
@interface RTCRtpTransceiverInit ()
|
||||||
|
|
||||||
@property(nonatomic, readonly) webrtc::RtpTransceiverInit nativeInit;
|
@property(nonatomic, readonly) webrtc::RtpTransceiverInit nativeInit;
|
||||||
@ -26,7 +28,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
nativeRtpTransceiver;
|
nativeRtpTransceiver;
|
||||||
|
|
||||||
/** Initialize an RTCRtpTransceiver with a native RtpTransceiverInterface. */
|
/** Initialize an RTCRtpTransceiver with a native RtpTransceiverInterface. */
|
||||||
- (instancetype)initWithNativeRtpTransceiver:
|
- (instancetype)initWithFactory:(RTCPeerConnectionFactory*)factory
|
||||||
|
nativeRtpTransceiver:
|
||||||
(rtc::scoped_refptr<webrtc::RtpTransceiverInterface>)nativeRtpTransceiver
|
(rtc::scoped_refptr<webrtc::RtpTransceiverInterface>)nativeRtpTransceiver
|
||||||
NS_DESIGNATED_INITIALIZER;
|
NS_DESIGNATED_INITIALIZER;
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation RTCRtpTransceiver {
|
@implementation RTCRtpTransceiver {
|
||||||
|
RTCPeerConnectionFactory *_factory;
|
||||||
rtc::scoped_refptr<webrtc::RtpTransceiverInterface> _nativeRtpTransceiver;
|
rtc::scoped_refptr<webrtc::RtpTransceiverInterface> _nativeRtpTransceiver;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,10 +121,13 @@
|
|||||||
return _nativeRtpTransceiver;
|
return _nativeRtpTransceiver;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithNativeRtpTransceiver:
|
- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
|
||||||
|
nativeRtpTransceiver:
|
||||||
(rtc::scoped_refptr<webrtc::RtpTransceiverInterface>)nativeRtpTransceiver {
|
(rtc::scoped_refptr<webrtc::RtpTransceiverInterface>)nativeRtpTransceiver {
|
||||||
|
NSParameterAssert(factory);
|
||||||
NSParameterAssert(nativeRtpTransceiver);
|
NSParameterAssert(nativeRtpTransceiver);
|
||||||
if (self = [super init]) {
|
if (self = [super init]) {
|
||||||
|
_factory = factory;
|
||||||
_nativeRtpTransceiver = nativeRtpTransceiver;
|
_nativeRtpTransceiver = nativeRtpTransceiver;
|
||||||
_sender = [[RTCRtpSender alloc] initWithNativeRtpSender:nativeRtpTransceiver->sender()];
|
_sender = [[RTCRtpSender alloc] initWithNativeRtpSender:nativeRtpTransceiver->sender()];
|
||||||
_receiver = [[RTCRtpReceiver alloc] initWithNativeRtpReceiver:nativeRtpTransceiver->receiver()];
|
_receiver = [[RTCRtpReceiver alloc] initWithNativeRtpReceiver:nativeRtpTransceiver->receiver()];
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#import <WebRTC/RTCMediaConstraints.h>
|
#import <WebRTC/RTCMediaConstraints.h>
|
||||||
#import <WebRTC/RTCPeerConnection.h>
|
#import <WebRTC/RTCPeerConnection.h>
|
||||||
#import <WebRTC/RTCPeerConnectionFactory.h>
|
#import <WebRTC/RTCPeerConnectionFactory.h>
|
||||||
|
#import <WebRTC/RTCRtpTransceiver.h>
|
||||||
|
|
||||||
#import <XCTest/XCTest.h>
|
#import <XCTest/XCTest.h>
|
||||||
|
|
||||||
@ -90,4 +91,32 @@
|
|||||||
XCTAssertTrue(true, "Expect test does not crash");
|
XCTAssertTrue(true, "Expect test does not crash");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)testRTCRtpTransceiverLifetime {
|
||||||
|
@autoreleasepool {
|
||||||
|
RTCConfiguration *config = [[RTCConfiguration alloc] init];
|
||||||
|
config.sdpSemantics = RTCSdpSemanticsUnifiedPlan;
|
||||||
|
RTCMediaConstraints *contraints =
|
||||||
|
[[RTCMediaConstraints alloc] initWithMandatoryConstraints:@{} optionalConstraints:nil];
|
||||||
|
RTCRtpTransceiverInit *init = [[RTCRtpTransceiverInit alloc] init];
|
||||||
|
|
||||||
|
RTCPeerConnectionFactory *factory;
|
||||||
|
RTCPeerConnection *peerConnection;
|
||||||
|
RTCRtpTransceiver *tranceiver;
|
||||||
|
|
||||||
|
@autoreleasepool {
|
||||||
|
factory = [[RTCPeerConnectionFactory alloc] init];
|
||||||
|
peerConnection =
|
||||||
|
[factory peerConnectionWithConfiguration:config constraints:contraints delegate:nil];
|
||||||
|
tranceiver = [peerConnection addTransceiverOfType:RTCRtpMediaTypeAudio init:init];
|
||||||
|
XCTAssertTrue(tranceiver != nil);
|
||||||
|
[peerConnection close];
|
||||||
|
peerConnection = nil;
|
||||||
|
factory = nil;
|
||||||
|
}
|
||||||
|
tranceiver = nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
XCTAssertTrue(true, "Expect test does not crash");
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
Reference in New Issue
Block a user