[PATCH 2/3] audiounit_ios: fix deadlock when interrupted

Carola Nitz nitz.carola at googlemail.com
Fri Dec 8 17:46:02 CET 2017


call ca_Pause() when the system is interrupting the audiosession.
Calling this function will wake up the decoder thread that may be waiting in play or flush
---
 modules/audio_output/audiounit_ios.m | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/modules/audio_output/audiounit_ios.m b/modules/audio_output/audiounit_ios.m
index a53a15f93d..3498baa089 100644
--- a/modules/audio_output/audiounit_ios.m
+++ b/modules/audio_output/audiounit_ios.m
@@ -127,6 +127,23 @@ - (void)audioSessionRouteChange:(NSNotification *)notification
         aout_RestartRequest(p_aout, AOUT_RESTART_OUTPUT);
 }
 
+- (void)handleInterruption:(NSNotification *)notification
+{
+    audio_output_t *p_aout = [self aout];
+    NSDictionary *userInfo = notification.userInfo;
+    if (!userInfo || !userInfo[AVAudioSessionInterruptionTypeKey]) {
+        return;
+    }
+
+    NSUInteger interruptionType = [userInfo[AVAudioSessionInterruptionTypeKey] unsignedIntegerValue];
+
+    if (interruptionType == AVAudioSessionInterruptionTypeBegan) {
+        ca_Pause(p_aout, true, 0);
+    } else if (interruptionType == AVAudioSessionInterruptionTypeEnded
+               && [userInfo[AVAudioSessionInterruptionOptionKey] unsignedIntegerValue] == AVAudioSessionInterruptionOptionShouldResume) {
+        ca_Pause(p_aout, false, 0);
+    }
+}
 @end
 
 static void
@@ -467,8 +484,13 @@ - (void)audioSessionRouteChange:(NSNotification *)notification
         Pause(p_aout, true, 0);
 
     [[NSNotificationCenter defaultCenter] addObserver:p_sys->aoutWrapper
-           selector:@selector(audioSessionRouteChange:)
-           name:AVAudioSessionRouteChangeNotification object:nil];
+                                             selector:@selector(audioSessionRouteChange:)
+                                                 name:AVAudioSessionRouteChangeNotification
+                                               object:nil];
+    [[NSNotificationCenter defaultCenter] addObserver:p_sys->aoutWrapper
+                                             selector:@selector(handleInterruption:)
+                                                 name:AVAudioSessionInterruptionNotification
+                                               object:nil];
 
     free(layout);
     fmt->channel_type = AUDIO_CHANNEL_TYPE_BITMAP;
-- 
2.13.5 (Apple Git-94)



More information about the vlc-devel mailing list