diff --git a/webrtc/examples/objc/AppRTCDemo/ARDAppClient.m b/webrtc/examples/objc/AppRTCDemo/ARDAppClient.m index 43eb6f4ad2..88431c6562 100644 --- a/webrtc/examples/objc/AppRTCDemo/ARDAppClient.m +++ b/webrtc/examples/objc/AppRTCDemo/ARDAppClient.m @@ -308,13 +308,11 @@ static int64_t const kARDAppClientRtcEventLogMaxSizeInBytes = 5e6; // 5 MB. _isInitiator = NO; _hasReceivedSdp = NO; _messageQueue = [NSMutableArray array]; -#if defined(WEBRTC_IOS) - [_peerConnection stopRtcEventLog]; -#endif _peerConnection = nil; self.state = kARDAppClientStateDisconnected; #if defined(WEBRTC_IOS) RTCStopInternalCapture(); + [_factory stopRtcEventLog]; #endif } @@ -528,6 +526,17 @@ static int64_t const kARDAppClientRtcEventLogMaxSizeInBytes = 5e6; // 5 MB. } self.state = kARDAppClientStateConnected; +#if defined(WEBRTC_IOS) + // Start event log. + if (kARDAppClientEnableRtcEventLog) { + NSString *filePath = [self documentsFilePathForFileName:@"webrtc-rtceventlog"]; + if (![_factory startRtcEventLogWithFilePath:filePath + maxSizeInBytes:kARDAppClientRtcEventLogMaxSizeInBytes]) { + RTCLogError(@"Failed to start event logging."); + } + } +#endif + // Create peer connection. RTCMediaConstraints *constraints = [self defaultPeerConnectionConstraints]; RTCConfiguration *config = [[RTCConfiguration alloc] init]; @@ -553,16 +562,6 @@ static int64_t const kARDAppClientRtcEventLogMaxSizeInBytes = 5e6; // 5 MB. // Check if we've received an offer. [self drainMessageQueueIfReady]; } -#if defined(WEBRTC_IOS) - // Start event log. - if (kARDAppClientEnableRtcEventLog) { - NSString *filePath = [self documentsFilePathForFileName:@"webrtc-rtceventlog"]; - if (![_peerConnection startRtcEventLogWithFilePath:filePath - maxSizeInBytes:kARDAppClientRtcEventLogMaxSizeInBytes]) { - RTCLogError(@"Failed to start event logging."); - } - } -#endif } // Processes the messages that we've received from the room server and the diff --git a/webrtc/sdk/objc/Framework/Classes/RTCPeerConnection.mm b/webrtc/sdk/objc/Framework/Classes/RTCPeerConnection.mm index 99a0db3d76..68d23874bd 100644 --- a/webrtc/sdk/objc/Framework/Classes/RTCPeerConnection.mm +++ b/webrtc/sdk/objc/Framework/Classes/RTCPeerConnection.mm @@ -207,7 +207,6 @@ void PeerConnectionDelegateAdapter::OnIceCandidatesRemoved( NSMutableArray *_localStreams; std::unique_ptr _observer; rtc::scoped_refptr _peerConnection; - BOOL _hasStartedRtcEventLog; } @synthesize delegate = _delegate; @@ -357,31 +356,6 @@ void PeerConnectionDelegateAdapter::OnIceCandidatesRemoved( _peerConnection->SetRemoteDescription(observer, sdp.nativeDescription); } -- (BOOL)startRtcEventLogWithFilePath:(NSString *)filePath - maxSizeInBytes:(int64_t)maxSizeInBytes { - RTC_DCHECK(filePath.length); - RTC_DCHECK_GT(maxSizeInBytes, 0); - RTC_DCHECK(!_hasStartedRtcEventLog); - if (_hasStartedRtcEventLog) { - RTCLogError(@"Event logging already started."); - return NO; - } - int fd = open(filePath.UTF8String, O_WRONLY | O_CREAT | O_TRUNC, - S_IRUSR | S_IWUSR); - if (fd < 0) { - RTCLogError(@"Error opening file: %@. Error: %d", filePath, errno); - return NO; - } - _hasStartedRtcEventLog = - _peerConnection->StartRtcEventLog(fd, maxSizeInBytes); - return _hasStartedRtcEventLog; -} - -- (void)stopRtcEventLog { - _peerConnection->StopRtcEventLog(); - _hasStartedRtcEventLog = NO; -} - - (RTCRtpSender *)senderWithKind:(NSString *)kind streamId:(NSString *)streamId { std::string nativeKind = [NSString stdStringForString:kind]; diff --git a/webrtc/sdk/objc/Framework/Classes/RTCPeerConnectionFactory.mm b/webrtc/sdk/objc/Framework/Classes/RTCPeerConnectionFactory.mm index 9c9fd75ac0..a1e701b0e4 100644 --- a/webrtc/sdk/objc/Framework/Classes/RTCPeerConnectionFactory.mm +++ b/webrtc/sdk/objc/Framework/Classes/RTCPeerConnectionFactory.mm @@ -10,6 +10,8 @@ #import "RTCPeerConnectionFactory+Private.h" +#include + #import "NSString+StdString.h" #import "RTCAVFoundationVideoSource+Private.h" #import "RTCAudioTrack+Private.h" @@ -17,11 +19,15 @@ #import "RTCPeerConnection+Private.h" #import "RTCVideoSource+Private.h" #import "RTCVideoTrack+Private.h" +#import "WebRTC/RTCLogging.h" + +#include "webrtc/base/checks.h" @implementation RTCPeerConnectionFactory { std::unique_ptr _networkThread; std::unique_ptr _workerThread; std::unique_ptr _signalingThread; + BOOL _hasStartedRtcEventLog; } @synthesize nativeFactory = _nativeFactory; @@ -48,6 +54,29 @@ return self; } +- (BOOL)startRtcEventLogWithFilePath:(NSString *)filePath + maxSizeInBytes:(int64_t)maxSizeInBytes { + RTC_DCHECK(filePath.length); + RTC_DCHECK_GT(maxSizeInBytes, 0); + RTC_DCHECK(!_hasStartedRtcEventLog); + if (_hasStartedRtcEventLog) { + RTCLogError(@"Event logging already started."); + return NO; + } + int fd = open(filePath.UTF8String, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); + if (fd < 0) { + RTCLogError(@"Error opening file: %@. Error: %d", filePath, errno); + return NO; + } + _hasStartedRtcEventLog = _nativeFactory->StartRtcEventLog(fd, maxSizeInBytes); + return _hasStartedRtcEventLog; +} + +- (void)stopRtcEventLog { + _nativeFactory->StopRtcEventLog(); + _hasStartedRtcEventLog = NO; +} + - (RTCAVFoundationVideoSource *)avFoundationVideoSourceWithConstraints: (nullable RTCMediaConstraints *)constraints { return [[RTCAVFoundationVideoSource alloc] initWithFactory:self diff --git a/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCPeerConnection.h b/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCPeerConnection.h index 87d643d101..922ccfa0ee 100644 --- a/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCPeerConnection.h +++ b/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCPeerConnection.h @@ -183,11 +183,6 @@ RTC_EXPORT completionHandler: (nullable void (^)(NSError * _Nullable error))completionHandler; -/** Start or stop recording an Rtc EventLog. */ -- (BOOL)startRtcEventLogWithFilePath:(NSString *)filePath - maxSizeInBytes:(int64_t)maxSizeInBytes; -- (void)stopRtcEventLog; - @end @interface RTCPeerConnection (Media) diff --git a/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCPeerConnectionFactory.h b/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCPeerConnectionFactory.h index f21c107581..f968ab7921 100644 --- a/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCPeerConnectionFactory.h +++ b/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCPeerConnectionFactory.h @@ -53,6 +53,11 @@ RTC_EXPORT delegate: (nullable id)delegate; +/** Temporary interface. Use at your own risk. See peerconnectioninterface.h for details. */ +- (BOOL)startRtcEventLogWithFilePath:(NSString *)filePath + maxSizeInBytes:(int64_t)maxSizeInBytes; +- (void)stopRtcEventLog; + @end NS_ASSUME_NONNULL_END