From 01cee079dcaab1979272a259da82804a4a7bce5e Mon Sep 17 00:00:00 2001 From: Yura Yaroshevich Date: Wed, 11 Jul 2018 15:35:40 +0300 Subject: [PATCH] Fixed crash when PCF is destroyed before MediaSource/Track in ObjC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: webrtc:9231 Change-Id: I31b86aa560f4ad230c9a94fedebebf320e0370a4 Reviewed-on: https://webrtc-review.googlesource.com/88221 Reviewed-by: Kári Helgason Commit-Queue: Kári Helgason Cr-Commit-Position: refs/heads/master@{#23981} --- .../PeerConnection/RTCAudioSource+Private.h | 10 +-- .../Classes/PeerConnection/RTCAudioSource.mm | 18 +++-- .../Classes/PeerConnection/RTCAudioTrack.mm | 14 ++-- .../PeerConnection/RTCMediaSource+Private.h | 8 ++- .../Classes/PeerConnection/RTCMediaSource.mm | 9 ++- .../Classes/PeerConnection/RTCMediaStream.mm | 4 +- .../RTCMediaStreamTrack+Private.h | 17 +++-- .../PeerConnection/RTCMediaStreamTrack.mm | 37 ++++++---- .../RTCPeerConnectionFactory.mm | 7 +- .../Classes/PeerConnection/RTCRtpReceiver.mm | 2 +- .../Classes/PeerConnection/RTCRtpSender.mm | 2 +- .../PeerConnection/RTCVideoSource+Private.h | 16 +++-- .../Classes/PeerConnection/RTCVideoSource.mm | 27 ++++--- .../Classes/PeerConnection/RTCVideoTrack.mm | 15 ++-- .../RTCPeerConnectionFactory_xctest.m | 70 +++++++++++++++++++ 15 files changed, 180 insertions(+), 76 deletions(-) diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCAudioSource+Private.h b/sdk/objc/Framework/Classes/PeerConnection/RTCAudioSource+Private.h index 752eb66c0b..63fff68892 100644 --- a/sdk/objc/Framework/Classes/PeerConnection/RTCAudioSource+Private.h +++ b/sdk/objc/Framework/Classes/PeerConnection/RTCAudioSource+Private.h @@ -21,12 +21,12 @@ @property(nonatomic, readonly) rtc::scoped_refptr nativeAudioSource; /** Initialize an RTCAudioSource from a native AudioSourceInterface. */ -- (instancetype)initWithNativeAudioSource: - (rtc::scoped_refptr)nativeAudioSource +- (instancetype)initWithFactory:(RTCPeerConnectionFactory*)factory + nativeAudioSource:(rtc::scoped_refptr)nativeAudioSource NS_DESIGNATED_INITIALIZER; -- (instancetype)initWithNativeMediaSource: - (rtc::scoped_refptr)nativeMediaSource - type:(RTCMediaSourceType)type NS_UNAVAILABLE; +- (instancetype)initWithFactory:(RTCPeerConnectionFactory*)factory + nativeMediaSource:(rtc::scoped_refptr)nativeMediaSource + type:(RTCMediaSourceType)type NS_UNAVAILABLE; @end diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCAudioSource.mm b/sdk/objc/Framework/Classes/PeerConnection/RTCAudioSource.mm index 310171d76b..a6822f6702 100644 --- a/sdk/objc/Framework/Classes/PeerConnection/RTCAudioSource.mm +++ b/sdk/objc/Framework/Classes/PeerConnection/RTCAudioSource.mm @@ -18,19 +18,23 @@ @synthesize volume = _volume; @synthesize nativeAudioSource = _nativeAudioSource; -- (instancetype)initWithNativeAudioSource: - (rtc::scoped_refptr)nativeAudioSource { +- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory + nativeAudioSource: + (rtc::scoped_refptr)nativeAudioSource { + RTC_DCHECK(factory); RTC_DCHECK(nativeAudioSource); - if (self = [super initWithNativeMediaSource:nativeAudioSource - type:RTCMediaSourceTypeAudio]) { + + if (self = [super initWithFactory:factory + nativeMediaSource:nativeAudioSource + type:RTCMediaSourceTypeAudio]) { _nativeAudioSource = nativeAudioSource; } return self; } -- (instancetype)initWithNativeMediaSource: - (rtc::scoped_refptr)nativeMediaSource - type:(RTCMediaSourceType)type { +- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory + nativeMediaSource:(rtc::scoped_refptr)nativeMediaSource + type:(RTCMediaSourceType)type { RTC_NOTREACHED(); return nil; } diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCAudioTrack.mm b/sdk/objc/Framework/Classes/PeerConnection/RTCAudioTrack.mm index e26088f59d..73de401eeb 100644 --- a/sdk/objc/Framework/Classes/PeerConnection/RTCAudioTrack.mm +++ b/sdk/objc/Framework/Classes/PeerConnection/RTCAudioTrack.mm @@ -31,18 +31,19 @@ std::string nativeId = [NSString stdStringForString:trackId]; rtc::scoped_refptr track = factory.nativeFactory->CreateAudioTrack(nativeId, source.nativeAudioSource); - if (self = [self initWithNativeTrack:track type:RTCMediaStreamTrackTypeAudio]) { + if (self = [self initWithFactory:factory nativeTrack:track type:RTCMediaStreamTrackTypeAudio]) { _source = source; } return self; } -- (instancetype)initWithNativeTrack: - (rtc::scoped_refptr)nativeTrack - type:(RTCMediaStreamTrackType)type { +- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory + nativeTrack:(rtc::scoped_refptr)nativeTrack + type:(RTCMediaStreamTrackType)type { + NSParameterAssert(factory); NSParameterAssert(nativeTrack); NSParameterAssert(type == RTCMediaStreamTrackTypeAudio); - return [super initWithNativeTrack:nativeTrack type:type]; + return [super initWithFactory:factory nativeTrack:nativeTrack type:type]; } @@ -51,7 +52,8 @@ rtc::scoped_refptr source = self.nativeAudioTrack->GetSource(); if (source) { - _source = [[RTCAudioSource alloc] initWithNativeAudioSource:source.get()]; + _source = + [[RTCAudioSource alloc] initWithFactory:self.factory nativeAudioSource:source.get()]; } } return _source; diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCMediaSource+Private.h b/sdk/objc/Framework/Classes/PeerConnection/RTCMediaSource+Private.h index f6382499fa..9883faf1c1 100644 --- a/sdk/objc/Framework/Classes/PeerConnection/RTCMediaSource+Private.h +++ b/sdk/objc/Framework/Classes/PeerConnection/RTCMediaSource+Private.h @@ -14,6 +14,8 @@ NS_ASSUME_NONNULL_BEGIN +@class RTCPeerConnectionFactory; + typedef NS_ENUM(NSInteger, RTCMediaSourceType) { RTCMediaSourceTypeAudio, RTCMediaSourceTypeVideo, @@ -23,9 +25,9 @@ typedef NS_ENUM(NSInteger, RTCMediaSourceType) { @property(nonatomic, readonly) rtc::scoped_refptr nativeMediaSource; -- (instancetype)initWithNativeMediaSource: - (rtc::scoped_refptr)nativeMediaSource - type:(RTCMediaSourceType)type NS_DESIGNATED_INITIALIZER; +- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory + nativeMediaSource:(rtc::scoped_refptr)nativeMediaSource + type:(RTCMediaSourceType)type NS_DESIGNATED_INITIALIZER; + (webrtc::MediaSourceInterface::SourceState)nativeSourceStateForState:(RTCSourceState)state; diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCMediaSource.mm b/sdk/objc/Framework/Classes/PeerConnection/RTCMediaSource.mm index 0f8cadc07d..6ec41c3b50 100644 --- a/sdk/objc/Framework/Classes/PeerConnection/RTCMediaSource.mm +++ b/sdk/objc/Framework/Classes/PeerConnection/RTCMediaSource.mm @@ -13,16 +13,19 @@ #include "rtc_base/checks.h" @implementation RTCMediaSource { + RTCPeerConnectionFactory *_factory; RTCMediaSourceType _type; } @synthesize nativeMediaSource = _nativeMediaSource; -- (instancetype)initWithNativeMediaSource: - (rtc::scoped_refptr)nativeMediaSource - type:(RTCMediaSourceType)type { +- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory + nativeMediaSource:(rtc::scoped_refptr)nativeMediaSource + type:(RTCMediaSourceType)type { + RTC_DCHECK(factory); RTC_DCHECK(nativeMediaSource); if (self = [super init]) { + _factory = factory; _nativeMediaSource = nativeMediaSource; _type = type; } diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCMediaStream.mm b/sdk/objc/Framework/Classes/PeerConnection/RTCMediaStream.mm index 52f1771438..c8bcfd91a4 100644 --- a/sdk/objc/Framework/Classes/PeerConnection/RTCMediaStream.mm +++ b/sdk/objc/Framework/Classes/PeerConnection/RTCMediaStream.mm @@ -109,14 +109,14 @@ for (auto &track : audioTracks) { RTCMediaStreamTrackType type = RTCMediaStreamTrackTypeAudio; RTCAudioTrack *audioTrack = - [[RTCAudioTrack alloc] initWithNativeTrack:track type:type]; + [[RTCAudioTrack alloc] initWithFactory:_factory nativeTrack:track type:type]; [_audioTracks addObject:audioTrack]; } for (auto &track : videoTracks) { RTCMediaStreamTrackType type = RTCMediaStreamTrackTypeVideo; RTCVideoTrack *videoTrack = - [[RTCVideoTrack alloc] initWithNativeTrack:track type:type]; + [[RTCVideoTrack alloc] initWithFactory:_factory nativeTrack:track type:type]; [_videoTracks addObject:videoTrack]; } } diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCMediaStreamTrack+Private.h b/sdk/objc/Framework/Classes/PeerConnection/RTCMediaStreamTrack+Private.h index bb24216a5d..6effeaac19 100644 --- a/sdk/objc/Framework/Classes/PeerConnection/RTCMediaStreamTrack+Private.h +++ b/sdk/objc/Framework/Classes/PeerConnection/RTCMediaStreamTrack+Private.h @@ -19,8 +19,12 @@ typedef NS_ENUM(NSInteger, RTCMediaStreamTrackType) { NS_ASSUME_NONNULL_BEGIN +@class RTCPeerConnectionFactory; + @interface RTCMediaStreamTrack () +@property(nonatomic, readonly) RTCPeerConnectionFactory *factory; + /** * The native MediaStreamTrackInterface passed in or created during * construction. @@ -30,12 +34,12 @@ NS_ASSUME_NONNULL_BEGIN /** * Initialize an RTCMediaStreamTrack from a native MediaStreamTrackInterface. */ -- (instancetype)initWithNativeTrack: - (rtc::scoped_refptr)nativeTrack - type:(RTCMediaStreamTrackType)type NS_DESIGNATED_INITIALIZER; +- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory + nativeTrack:(rtc::scoped_refptr)nativeTrack + type:(RTCMediaStreamTrackType)type NS_DESIGNATED_INITIALIZER; -- (instancetype)initWithNativeTrack: - (rtc::scoped_refptr)nativeTrack; +- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory + nativeTrack:(rtc::scoped_refptr)nativeTrack; - (BOOL)isEqualToTrack:(RTCMediaStreamTrack *)track; @@ -48,7 +52,8 @@ NS_ASSUME_NONNULL_BEGIN + (NSString *)stringForState:(RTCMediaStreamTrackState)state; + (RTCMediaStreamTrack *)mediaTrackForNativeTrack: - (rtc::scoped_refptr)nativeTrack; + (rtc::scoped_refptr)nativeTrack + factory:(RTCPeerConnectionFactory *)factory; @end diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCMediaStreamTrack.mm b/sdk/objc/Framework/Classes/PeerConnection/RTCMediaStreamTrack.mm index 5c1b5a39ab..07bb0094c1 100644 --- a/sdk/objc/Framework/Classes/PeerConnection/RTCMediaStreamTrack.mm +++ b/sdk/objc/Framework/Classes/PeerConnection/RTCMediaStreamTrack.mm @@ -20,6 +20,7 @@ NSString * const kRTCMediaStreamTrackKindVideo = @(webrtc::MediaStreamTrackInterface::kVideoKind); @implementation RTCMediaStreamTrack { + RTCPeerConnectionFactory *_factory; rtc::scoped_refptr _nativeTrack; RTCMediaStreamTrackType _type; } @@ -73,29 +74,31 @@ NSString * const kRTCMediaStreamTrackKindVideo = return _nativeTrack; } -- (instancetype)initWithNativeTrack: - (rtc::scoped_refptr)nativeTrack - type:(RTCMediaStreamTrackType)type { +@synthesize factory = _factory; + +- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory + nativeTrack:(rtc::scoped_refptr)nativeTrack + type:(RTCMediaStreamTrackType)type { NSParameterAssert(nativeTrack); + NSParameterAssert(factory); if (self = [super init]) { + _factory = factory; _nativeTrack = nativeTrack; _type = type; } return self; } -- (instancetype)initWithNativeTrack: - (rtc::scoped_refptr)nativeTrack { +- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory + nativeTrack:(rtc::scoped_refptr)nativeTrack { NSParameterAssert(nativeTrack); if (nativeTrack->kind() == std::string(webrtc::MediaStreamTrackInterface::kAudioKind)) { - return [self initWithNativeTrack:nativeTrack - type:RTCMediaStreamTrackTypeAudio]; + return [self initWithFactory:factory nativeTrack:nativeTrack type:RTCMediaStreamTrackTypeAudio]; } if (nativeTrack->kind() == std::string(webrtc::MediaStreamTrackInterface::kVideoKind)) { - return [self initWithNativeTrack:nativeTrack - type:RTCMediaStreamTrackTypeVideo]; + return [self initWithFactory:factory nativeTrack:nativeTrack type:RTCMediaStreamTrackTypeVideo]; } return nil; } @@ -137,16 +140,20 @@ NSString * const kRTCMediaStreamTrackKindVideo = } + (RTCMediaStreamTrack *)mediaTrackForNativeTrack: - (rtc::scoped_refptr)nativeTrack { + (rtc::scoped_refptr)nativeTrack + factory:(RTCPeerConnectionFactory *)factory { NSParameterAssert(nativeTrack); + NSParameterAssert(factory); if (nativeTrack->kind() == webrtc::MediaStreamTrackInterface::kAudioKind) { - return - [[RTCAudioTrack alloc] initWithNativeTrack:nativeTrack type:RTCMediaStreamTrackTypeAudio]; + return [[RTCAudioTrack alloc] initWithFactory:factory + nativeTrack:nativeTrack + type:RTCMediaStreamTrackTypeAudio]; } else if (nativeTrack->kind() == webrtc::MediaStreamTrackInterface::kVideoKind) { - return - [[RTCVideoTrack alloc] initWithNativeTrack:nativeTrack type:RTCMediaStreamTrackTypeVideo]; + return [[RTCVideoTrack alloc] initWithFactory:factory + nativeTrack:nativeTrack + type:RTCMediaStreamTrackTypeVideo]; } else { - return [[RTCMediaStreamTrack alloc] initWithNativeTrack:nativeTrack]; + return [[RTCMediaStreamTrack alloc] initWithFactory:factory nativeTrack:nativeTrack]; } } diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactory.mm b/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactory.mm index 4061c0266b..4c801f05d6 100644 --- a/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactory.mm +++ b/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactory.mm @@ -180,7 +180,7 @@ rtc::scoped_refptr source = _nativeFactory->CreateAudioSource(options); - return [[RTCAudioSource alloc] initWithNativeAudioSource:source]; + return [[RTCAudioSource alloc] initWithFactory:self nativeAudioSource:source]; } - (RTCAudioTrack *)audioTrackWithTrackId:(NSString *)trackId { @@ -196,8 +196,9 @@ } - (RTCVideoSource *)videoSource { - return [[RTCVideoSource alloc] initWithSignalingThread:_signalingThread.get() - workerThread:_workerThread.get()]; + return [[RTCVideoSource alloc] initWithFactory:self + signalingThread:_signalingThread.get() + workerThread:_workerThread.get()]; } - (RTCVideoTrack *)videoTrackWithSource:(RTCVideoSource *)source diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCRtpReceiver.mm b/sdk/objc/Framework/Classes/PeerConnection/RTCRtpReceiver.mm index 1342c166c0..895c451a04 100644 --- a/sdk/objc/Framework/Classes/PeerConnection/RTCRtpReceiver.mm +++ b/sdk/objc/Framework/Classes/PeerConnection/RTCRtpReceiver.mm @@ -63,7 +63,7 @@ void RtpReceiverDelegateAdapter::OnFirstPacketReceived( rtc::scoped_refptr nativeTrack( _nativeRtpReceiver->track()); if (nativeTrack) { - return [RTCMediaStreamTrack mediaTrackForNativeTrack:nativeTrack]; + return [RTCMediaStreamTrack mediaTrackForNativeTrack:nativeTrack factory:_factory]; } return nil; } diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCRtpSender.mm b/sdk/objc/Framework/Classes/PeerConnection/RTCRtpSender.mm index 1df7ae5a21..6a46edfef3 100644 --- a/sdk/objc/Framework/Classes/PeerConnection/RTCRtpSender.mm +++ b/sdk/objc/Framework/Classes/PeerConnection/RTCRtpSender.mm @@ -45,7 +45,7 @@ rtc::scoped_refptr nativeTrack( _nativeRtpSender->track()); if (nativeTrack) { - return [RTCMediaStreamTrack mediaTrackForNativeTrack:nativeTrack]; + return [RTCMediaStreamTrack mediaTrackForNativeTrack:nativeTrack factory:_factory]; } return nil; } diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCVideoSource+Private.h b/sdk/objc/Framework/Classes/PeerConnection/RTCVideoSource+Private.h index fdb45224c9..5eea2f9896 100644 --- a/sdk/objc/Framework/Classes/PeerConnection/RTCVideoSource+Private.h +++ b/sdk/objc/Framework/Classes/PeerConnection/RTCVideoSource+Private.h @@ -26,16 +26,18 @@ NS_ASSUME_NONNULL_BEGIN nativeVideoSource; /** Initialize an RTCVideoSource from a native VideoTrackSourceInterface. */ -- (instancetype)initWithNativeVideoSource: - (rtc::scoped_refptr)nativeVideoSource +- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory + nativeVideoSource: + (rtc::scoped_refptr)nativeVideoSource NS_DESIGNATED_INITIALIZER; -- (instancetype)initWithNativeMediaSource: - (rtc::scoped_refptr)nativeMediaSource - type:(RTCMediaSourceType)type NS_UNAVAILABLE; +- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory + nativeMediaSource:(rtc::scoped_refptr)nativeMediaSource + type:(RTCMediaSourceType)type NS_UNAVAILABLE; -- (instancetype)initWithSignalingThread:(rtc::Thread *)signalingThread - workerThread:(rtc::Thread *)workerThread; +- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory + signalingThread:(rtc::Thread *)signalingThread + workerThread:(rtc::Thread *)workerThread; @end diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCVideoSource.mm b/sdk/objc/Framework/Classes/PeerConnection/RTCVideoSource.mm index f380af4558..63b80144cf 100644 --- a/sdk/objc/Framework/Classes/PeerConnection/RTCVideoSource.mm +++ b/sdk/objc/Framework/Classes/PeerConnection/RTCVideoSource.mm @@ -28,30 +28,35 @@ static webrtc::ObjCVideoTrackSource *getObjCVideoSource( rtc::scoped_refptr _nativeVideoSource; } -- (instancetype)initWithNativeVideoSource: - (rtc::scoped_refptr)nativeVideoSource { +- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory + nativeVideoSource: + (rtc::scoped_refptr)nativeVideoSource { + RTC_DCHECK(factory); RTC_DCHECK(nativeVideoSource); - if (self = [super initWithNativeMediaSource:nativeVideoSource - type:RTCMediaSourceTypeVideo]) { + if (self = [super initWithFactory:factory + nativeMediaSource:nativeVideoSource + type:RTCMediaSourceTypeVideo]) { _nativeVideoSource = nativeVideoSource; } return self; } -- (instancetype)initWithNativeMediaSource: - (rtc::scoped_refptr)nativeMediaSource - type:(RTCMediaSourceType)type { +- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory + nativeMediaSource:(rtc::scoped_refptr)nativeMediaSource + type:(RTCMediaSourceType)type { RTC_NOTREACHED(); return nil; } -- (instancetype)initWithSignalingThread:(rtc::Thread *)signalingThread - workerThread:(rtc::Thread *)workerThread { +- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory + signalingThread:(rtc::Thread *)signalingThread + workerThread:(rtc::Thread *)workerThread { rtc::scoped_refptr objCVideoTrackSource( new rtc::RefCountedObject()); - return [self initWithNativeVideoSource:webrtc::VideoTrackSourceProxy::Create( - signalingThread, workerThread, objCVideoTrackSource)]; + return [self initWithFactory:factory + nativeVideoSource:webrtc::VideoTrackSourceProxy::Create( + signalingThread, workerThread, objCVideoTrackSource)]; } - (NSString *)description { diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCVideoTrack.mm b/sdk/objc/Framework/Classes/PeerConnection/RTCVideoTrack.mm index 2f03110739..c9eb35c875 100644 --- a/sdk/objc/Framework/Classes/PeerConnection/RTCVideoTrack.mm +++ b/sdk/objc/Framework/Classes/PeerConnection/RTCVideoTrack.mm @@ -32,18 +32,20 @@ rtc::scoped_refptr track = factory.nativeFactory->CreateVideoTrack(nativeId, source.nativeVideoSource); - if (self = [self initWithNativeTrack:track type:RTCMediaStreamTrackTypeVideo]) { + if (self = [self initWithFactory:factory nativeTrack:track type:RTCMediaStreamTrackTypeVideo]) { _source = source; } return self; } -- (instancetype)initWithNativeTrack: - (rtc::scoped_refptr)nativeMediaTrack - type:(RTCMediaStreamTrackType)type { +- (instancetype)initWithFactory:(RTCPeerConnectionFactory *)factory + nativeTrack: + (rtc::scoped_refptr)nativeMediaTrack + type:(RTCMediaStreamTrackType)type { + NSParameterAssert(factory); NSParameterAssert(nativeMediaTrack); NSParameterAssert(type == RTCMediaStreamTrackTypeVideo); - if (self = [super initWithNativeTrack:nativeMediaTrack type:type]) { + if (self = [super initWithFactory:factory nativeTrack:nativeMediaTrack type:type]) { _adapters = [NSMutableArray array]; } return self; @@ -60,7 +62,8 @@ rtc::scoped_refptr source = self.nativeVideoTrack->GetSource(); if (source) { - _source = [[RTCVideoSource alloc] initWithNativeVideoSource:source.get()]; + _source = + [[RTCVideoSource alloc] initWithFactory:self.factory nativeVideoSource:source.get()]; } } return _source; diff --git a/sdk/objc/Framework/UnitTests/RTCPeerConnectionFactory_xctest.m b/sdk/objc/Framework/UnitTests/RTCPeerConnectionFactory_xctest.m index eecc289dc9..5608c69dbc 100644 --- a/sdk/objc/Framework/UnitTests/RTCPeerConnectionFactory_xctest.m +++ b/sdk/objc/Framework/UnitTests/RTCPeerConnectionFactory_xctest.m @@ -8,6 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ +#import #import #import #import @@ -18,6 +19,7 @@ #import #import #import +#import #import @@ -193,6 +195,74 @@ XCTAssertTrue(true, "Expect test does not crash"); } +- (void)testAudioSourceLifetime { + @autoreleasepool { + RTCPeerConnectionFactory *factory; + RTCAudioSource *audioSource; + + @autoreleasepool { + factory = [[RTCPeerConnectionFactory alloc] init]; + audioSource = [factory audioSourceWithConstraints:nil]; + XCTAssertNotNil(audioSource); + factory = nil; + } + audioSource = nil; + } + + XCTAssertTrue(true, "Expect test does not crash"); +} + +- (void)testVideoSourceLifetime { + @autoreleasepool { + RTCPeerConnectionFactory *factory; + RTCVideoSource *videoSource; + + @autoreleasepool { + factory = [[RTCPeerConnectionFactory alloc] init]; + videoSource = [factory videoSource]; + XCTAssertNotNil(videoSource); + factory = nil; + } + videoSource = nil; + } + + XCTAssertTrue(true, "Expect test does not crash"); +} + +- (void)testAudioTrackLifetime { + @autoreleasepool { + RTCPeerConnectionFactory *factory; + RTCAudioTrack *audioTrack; + + @autoreleasepool { + factory = [[RTCPeerConnectionFactory alloc] init]; + audioTrack = [factory audioTrackWithTrackId:@"audioTrack"]; + XCTAssertNotNil(audioTrack); + factory = nil; + } + audioTrack = nil; + } + + XCTAssertTrue(true, "Expect test does not crash"); +} + +- (void)testVideoTrackLifetime { + @autoreleasepool { + RTCPeerConnectionFactory *factory; + RTCVideoTrack *videoTrack; + + @autoreleasepool { + factory = [[RTCPeerConnectionFactory alloc] init]; + videoTrack = [factory videoTrackWithSource:[factory videoSource] trackId:@"videoTrack"]; + XCTAssertNotNil(videoTrack); + factory = nil; + } + videoTrack = nil; + } + + XCTAssertTrue(true, "Expect test does not crash"); +} + - (bool)negotiatePeerConnection:(RTCPeerConnection *)pc1 withPeerConnection:(RTCPeerConnection *)pc2 negotiationTimeout:(NSTimeInterval)timeout {