diff --git a/webrtc/examples/objc/AppRTCDemo/ARDAppClient+Internal.h b/webrtc/examples/objc/AppRTCDemo/ARDAppClient+Internal.h index 4a69899364..a21ac72aee 100644 --- a/webrtc/examples/objc/AppRTCDemo/ARDAppClient+Internal.h +++ b/webrtc/examples/objc/AppRTCDemo/ARDAppClient+Internal.h @@ -44,7 +44,6 @@ @property(nonatomic, readonly) BOOL isLoopback; @property(nonatomic, readonly) BOOL isAudioOnly; @property(nonatomic, readonly) BOOL shouldMakeAecDump; -@property(nonatomic, assign) BOOL isAecDumpActive; @property(nonatomic, readonly) BOOL shouldUseLevelControl; @property(nonatomic, strong) diff --git a/webrtc/examples/objc/AppRTCDemo/ARDAppClient.m b/webrtc/examples/objc/AppRTCDemo/ARDAppClient.m index ea86c5ed48..9f61951670 100644 --- a/webrtc/examples/objc/AppRTCDemo/ARDAppClient.m +++ b/webrtc/examples/objc/AppRTCDemo/ARDAppClient.m @@ -58,6 +58,7 @@ static NSString * const kARDVideoTrackId = @"ARDAMSv0"; // TODO(tkchin): Add these as UI options. static BOOL const kARDAppClientEnableTracing = NO; static BOOL const kARDAppClientEnableRtcEventLog = YES; +static int64_t const kARDAppClientAecDumpMaxSizeInBytes = 5e6; // 5 MB. static int64_t const kARDAppClientRtcEventLogMaxSizeInBytes = 5e6; // 5 MB. #endif @@ -130,7 +131,6 @@ static int64_t const kARDAppClientRtcEventLogMaxSizeInBytes = 5e6; // 5 MB. @synthesize isLoopback = _isLoopback; @synthesize isAudioOnly = _isAudioOnly; @synthesize shouldMakeAecDump = _shouldMakeAecDump; -@synthesize isAecDumpActive = _isAecDumpActive; @synthesize shouldUseLevelControl = _shouldUseLevelControl; - (instancetype)init { @@ -316,10 +316,7 @@ static int64_t const kARDAppClientRtcEventLogMaxSizeInBytes = 5e6; // 5 MB. _hasReceivedSdp = NO; _messageQueue = [NSMutableArray array]; #if defined(WEBRTC_IOS) - if (_isAecDumpActive) { - [_factory stopAecDump]; - _isAecDumpActive = NO; - } + [_factory stopAecDump]; [_peerConnection stopRtcEventLog]; #endif _peerConnection = nil; @@ -576,17 +573,10 @@ static int64_t const kARDAppClientRtcEventLogMaxSizeInBytes = 5e6; // 5 MB. // Start aecdump diagnostic recording. if (_shouldMakeAecDump) { - _isAecDumpActive = YES; - NSString *filePath = [self documentsFilePathForFileName:@"audio.aecdump"]; - int fd = open(filePath.UTF8String, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); - if (fd < 0) { - RTCLogError(@"Failed to create the aecdump file!"); - _isAecDumpActive = NO; - } else { - if (![_factory startAecDumpWithFileDescriptor:fd maxFileSizeInBytes:-1]) { - RTCLogError(@"Failed to create aecdump."); - _isAecDumpActive = NO; - } + NSString *filePath = [self documentsFilePathForFileName:@"webrtc-audio.aecdump"]; + if (![_factory startAecDumpWithFilePath:filePath + maxSizeInBytes:kARDAppClientAecDumpMaxSizeInBytes]) { + RTCLogError(@"Failed to start aec dump."); } } #endif diff --git a/webrtc/sdk/objc/Framework/Classes/RTCPeerConnectionFactory.mm b/webrtc/sdk/objc/Framework/Classes/RTCPeerConnectionFactory.mm index d5fd1df067..9f24aec11d 100644 --- a/webrtc/sdk/objc/Framework/Classes/RTCPeerConnectionFactory.mm +++ b/webrtc/sdk/objc/Framework/Classes/RTCPeerConnectionFactory.mm @@ -19,11 +19,13 @@ #import "RTCPeerConnection+Private.h" #import "RTCVideoSource+Private.h" #import "RTCVideoTrack+Private.h" +#import "WebRTC/RTCLogging.h" @implementation RTCPeerConnectionFactory { std::unique_ptr _networkThread; std::unique_ptr _workerThread; std::unique_ptr _signalingThread; + BOOL _hasStartedAecDump; } @synthesize nativeFactory = _nativeFactory; @@ -50,19 +52,6 @@ return self; } -- (BOOL)startAecDumpWithFileDescriptor:(int)fileDescriptor - maxFileSizeInBytes:(int)maxFileSizeInBytes { - // Pass the file to the recorder. The file ownership - // is passed to the recorder, and the recorder - // closes the file when needed. - return _nativeFactory->StartAecDump(fileDescriptor, maxFileSizeInBytes); -} - -- (void)stopAecDump { - // The file is closed by the call below. - _nativeFactory->StopAecDump(); -} - - (RTCAudioSource *)audioSourceWithConstraints:(nullable RTCMediaConstraints *)constraints { std::unique_ptr nativeConstraints; if (constraints) { @@ -115,4 +104,27 @@ delegate:delegate]; } +- (BOOL)startAecDumpWithFilePath:(NSString *)filePath + maxSizeInBytes:(int64_t)maxSizeInBytes { + RTC_DCHECK(filePath.length); + RTC_DCHECK_GT(maxSizeInBytes, 0); + + if (_hasStartedAecDump) { + RTCLogError(@"Aec dump 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; + } + _hasStartedAecDump = _nativeFactory->StartAecDump(fd, maxSizeInBytes); + return _hasStartedAecDump; +} + +- (void)stopAecDump { + _nativeFactory->StopAecDump(); + _hasStartedAecDump = NO; +} + @end diff --git a/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCPeerConnectionFactory.h b/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCPeerConnectionFactory.h index 03279a3c7b..2088163eec 100644 --- a/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCPeerConnectionFactory.h +++ b/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCPeerConnectionFactory.h @@ -63,14 +63,11 @@ RTC_EXPORT delegate: (nullable id)delegate; -/** Start an aecdump recording with a file descriptor and - a specified maximum size limit (-1 specifies that no - limit should be used). - This API call will likely change in the future */ -- (BOOL)startAecDumpWithFileDescriptor:(int)fileDescriptor - maxFileSizeInBytes:(int)maxFileSizeInBytes; +/** Start an AecDump recording. This API call will likely change in the future. */ +- (BOOL)startAecDumpWithFilePath:(NSString *)filePath + maxSizeInBytes:(int64_t)maxSizeInBytes; -/* Stop an active aecdump recording */ +/* Stop an active AecDump recording */ - (void)stopAecDump; @end