Fixed crash when PCF is destroyed before DataChannel in ObjC

Bug: webrtc:9231
Change-Id: Ifad698b366be61d33ffca81cf4f8ca8aba2988a2
Reviewed-on: https://webrtc-review.googlesource.com/86040
Reviewed-by: Kári Helgason <kthelgason@webrtc.org>
Commit-Queue: Kári Helgason <kthelgason@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23771}
This commit is contained in:
Yura Yaroshevich
2018-06-27 17:09:14 +03:00
committed by Commit Bot
parent 33b61ee81e
commit c75b35ab40
5 changed files with 42 additions and 7 deletions

View File

@ -15,6 +15,8 @@
NS_ASSUME_NONNULL_BEGIN
@class RTCPeerConnectionFactory;
@interface RTCDataBuffer ()
/**
@ -31,8 +33,8 @@ NS_ASSUME_NONNULL_BEGIN
@interface RTCDataChannel ()
/** Initialize an RTCDataChannel from a native DataChannelInterface. */
- (instancetype)initWithNativeDataChannel:
(rtc::scoped_refptr<webrtc::DataChannelInterface>)nativeDataChannel
- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
nativeDataChannel:(rtc::scoped_refptr<webrtc::DataChannelInterface>)nativeDataChannel
NS_DESIGNATED_INITIALIZER;
+ (webrtc::DataChannelInterface::DataState)nativeDataChannelStateForState:

View File

@ -85,6 +85,7 @@ class DataChannelDelegateAdapter : public DataChannelObserver {
@implementation RTCDataChannel {
RTCPeerConnectionFactory *_factory;
rtc::scoped_refptr<webrtc::DataChannelInterface> _nativeDataChannel;
std::unique_ptr<webrtc::DataChannelDelegateAdapter> _observer;
BOOL _isObserverRegistered;
@ -165,10 +166,12 @@ class DataChannelDelegateAdapter : public DataChannelObserver {
#pragma mark - Private
- (instancetype)initWithNativeDataChannel:
(rtc::scoped_refptr<webrtc::DataChannelInterface>)nativeDataChannel {
- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory
nativeDataChannel:
(rtc::scoped_refptr<webrtc::DataChannelInterface>)nativeDataChannel {
NSParameterAssert(nativeDataChannel);
if (self = [super init]) {
_factory = factory;
_nativeDataChannel = nativeDataChannel;
_observer.reset(new webrtc::DataChannelDelegateAdapter(self));
_nativeDataChannel->RegisterObserver(_observer.get());

View File

@ -27,7 +27,7 @@
if (!dataChannel) {
return nil;
}
return [[RTCDataChannel alloc] initWithNativeDataChannel:dataChannel];
return [[RTCDataChannel alloc] initWithFactory:self.factory nativeDataChannel:dataChannel];
}
@end

View File

@ -163,9 +163,9 @@ void PeerConnectionDelegateAdapter::OnTrack(
void PeerConnectionDelegateAdapter::OnDataChannel(
rtc::scoped_refptr<DataChannelInterface> data_channel) {
RTCDataChannel *dataChannel =
[[RTCDataChannel alloc] initWithNativeDataChannel:data_channel];
RTCPeerConnection *peer_connection = peer_connection_;
RTCDataChannel *dataChannel = [[RTCDataChannel alloc] initWithFactory:peer_connection.factory
nativeDataChannel:data_channel];
[peer_connection.delegate peerConnection:peer_connection
didOpenDataChannel:dataChannel];
}