diff --git a/webrtc/examples/objc/AppRTCMobile/ios/ARDVideoCallViewController.m b/webrtc/examples/objc/AppRTCMobile/ios/ARDVideoCallViewController.m index 03ce626266..ad5bc80d4b 100644 --- a/webrtc/examples/objc/AppRTCMobile/ios/ARDVideoCallViewController.m +++ b/webrtc/examples/objc/AppRTCMobile/ios/ARDVideoCallViewController.m @@ -22,7 +22,8 @@ #import "WebRTC/RTCMediaConstraints.h" @interface ARDVideoCallViewController () + ARDVideoCallViewDelegate, + RTCAudioSessionDelegate> @property(nonatomic, strong) RTCVideoTrack *remoteVideoTrack; @property(nonatomic, readonly) ARDVideoCallView *videoCallView; @end @@ -57,6 +58,9 @@ _videoCallView.statusLabel.text = [self statusTextForState:RTCIceConnectionStateNew]; self.view = _videoCallView; + + RTCAudioSession *session = [RTCAudioSession sharedInstance]; + [session addDelegate:self]; } #pragma mark - ARDAppClientDelegate @@ -158,6 +162,13 @@ _videoCallView.statsView.hidden = NO; } +#pragma mark - RTCAudioSessionDelegate + +- (void)audioSession:(RTCAudioSession *)audioSession + didDetectPlayoutGlitch:(int64_t)totalNumberOfGlitches { + RTCLog(@"Audio session detected glitch, total: %lld", totalNumberOfGlitches); +} + #pragma mark - Private - (void)setRemoteVideoTrack:(RTCVideoTrack *)remoteVideoTrack { diff --git a/webrtc/modules/audio_device/ios/audio_device_ios.mm b/webrtc/modules/audio_device/ios/audio_device_ios.mm index de05bf11a2..1dfca0749e 100644 --- a/webrtc/modules/audio_device/ios/audio_device_ios.mm +++ b/webrtc/modules/audio_device/ios/audio_device_ios.mm @@ -672,6 +672,12 @@ void AudioDeviceIOS::HandlePlayoutGlitchDetected() { num_detected_playout_glitches_++; RTCLog(@"Number of detected playout glitches: %lld", num_detected_playout_glitches_); + + int64_t glitch_count = num_detected_playout_glitches_; + dispatch_async(dispatch_get_main_queue(), ^{ + RTCAudioSession* session = [RTCAudioSession sharedInstance]; + [session notifyDidDetectPlayoutGlitch:glitch_count]; + }); } void AudioDeviceIOS::HandleOutputVolumeChange() { diff --git a/webrtc/sdk/objc/Framework/Classes/Audio/RTCAudioSession+Private.h b/webrtc/sdk/objc/Framework/Classes/Audio/RTCAudioSession+Private.h index 5a063ed902..cd95ba654d 100644 --- a/webrtc/sdk/objc/Framework/Classes/Audio/RTCAudioSession+Private.h +++ b/webrtc/sdk/objc/Framework/Classes/Audio/RTCAudioSession+Private.h @@ -90,6 +90,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)notifyDidChangeCanPlayOrRecord:(BOOL)canPlayOrRecord; - (void)notifyDidStartPlayOrRecord; - (void)notifyDidStopPlayOrRecord; +- (void)notifyDidDetectPlayoutGlitch:(int64_t)totalNumberOfGlitches; @end diff --git a/webrtc/sdk/objc/Framework/Classes/Audio/RTCAudioSession.mm b/webrtc/sdk/objc/Framework/Classes/Audio/RTCAudioSession.mm index ce0e2633f9..bf27674101 100644 --- a/webrtc/sdk/objc/Framework/Classes/Audio/RTCAudioSession.mm +++ b/webrtc/sdk/objc/Framework/Classes/Audio/RTCAudioSession.mm @@ -914,4 +914,13 @@ NSString * const kRTCAudioSessionOutputVolumeSelector = @"outputVolume"; } } +- (void)notifyDidDetectPlayoutGlitch:(int64_t)totalNumberOfGlitches { + for (auto delegate : self.delegates) { + SEL sel = @selector(audioSession:didDetectPlayoutGlitch:); + if ([delegate respondsToSelector:sel]) { + [delegate audioSession:self didDetectPlayoutGlitch:totalNumberOfGlitches]; + } + } +} + @end diff --git a/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCAudioSession.h b/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCAudioSession.h index c0ea2163ae..f99c835b51 100644 --- a/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCAudioSession.h +++ b/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCAudioSession.h @@ -78,6 +78,12 @@ RTC_EXPORT - (void)audioSession:(RTCAudioSession *)audioSession didChangeOutputVolume:(float)outputVolume; +/** Called when the audio device detects a playout glitch. The argument is the + * number of glitches detected so far in the current audio playout session. + */ +- (void)audioSession:(RTCAudioSession *)audioSession + didDetectPlayoutGlitch:(int64_t)totalNumberOfGlitches; + @end /** This is a protocol used to inform RTCAudioSession when the audio session