[vlc-commits] iOS audio unit: improve session handling for parallel playback instances

Felix Paul Kühne git at videolan.org
Sat Jun 2 15:58:32 CEST 2018


vlc/vlc-3.0 | branch: master | Felix Paul Kühne <felix at feepk.net> | Mon May 28 19:36:38 2018 +0200| [0ed65ca0833aea3b5e950da290c469942543bec7] | committer: Felix Paul Kühne

iOS audio unit: improve session handling for parallel playback instances

Previously, playback was terminated once the first audio track stopped instead of the last

(cherry picked from commit 5a59782d4506183c944a8f027fd0d94767e65f7b)

> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=0ed65ca0833aea3b5e950da290c469942543bec7
---

 modules/audio_output/audiounit_ios.m | 57 ++++++++++++++++++++++++++++++++++--
 1 file changed, 55 insertions(+), 2 deletions(-)

diff --git a/modules/audio_output/audiounit_ios.m b/modules/audio_output/audiounit_ios.m
index 0649d30417..d17f5eaad8 100644
--- a/modules/audio_output/audiounit_ios.m
+++ b/modules/audio_output/audiounit_ios.m
@@ -72,6 +72,53 @@ static const struct {
       AU_DEV_ENCODED }, /* This can also be forced with the --spdif option */
 };
 
+ at interface SessionManager : NSObject
+{
+    NSMutableSet *_registeredInstances;
+}
++ (SessionManager *)sharedInstance;
+- (void)addAoutInstance:(AoutWrapper *)wrapperInstance;
+- (NSInteger)removeAoutInstance:(AoutWrapper *)wrapperInstance;
+ at end
+
+ at implementation SessionManager
++ (SessionManager *)sharedInstance
+{
+    static SessionManager *sharedInstance = nil;
+    static dispatch_once_t pred;
+
+    dispatch_once(&pred, ^{
+        sharedInstance = [SessionManager new];
+    });
+
+    return sharedInstance;
+}
+
+- (instancetype)init
+{
+    self = [super init];
+    if (self) {
+        _registeredInstances = [[NSMutableSet alloc] init];
+    }
+    return self;
+}
+
+- (void)addAoutInstance:(AoutWrapper *)wrapperInstance
+{
+    @synchronized(_registeredInstances) {
+        [_registeredInstances addObject:wrapperInstance];
+    }
+}
+
+- (NSInteger)removeAoutInstance:(AoutWrapper *)wrapperInstance
+{
+    @synchronized(_registeredInstances) {
+        [_registeredInstances removeObject:wrapperInstance];
+        return _registeredInstances.count;
+    }
+}
+ at end
+
 /*****************************************************************************
  * aout_sys_t: private audio output method descriptor
  *****************************************************************************
@@ -294,9 +341,15 @@ avas_SetActive(audio_output_t *p_aout, bool active, NSUInteger options)
         ret = [instance setCategory:AVAudioSessionCategoryPlayback error:&error];
         ret = ret && [instance setMode:AVAudioSessionModeMoviePlayback error:&error];
         ret = ret && [instance setActive:YES withOptions:options error:&error];
+        [[SessionManager sharedInstance] addAoutInstance: p_sys->aoutWrapper];
+    } else {
+        NSInteger numberOfRegisteredInstances = [[SessionManager sharedInstance] removeAoutInstance: p_sys->aoutWrapper];
+        if (numberOfRegisteredInstances == 0) {
+            ret = [instance setActive:NO withOptions:options error:&error];
+        } else {
+            ret = true;
+        }
     }
-    else
-        ret = [instance setActive:NO withOptions:options error:&error];
 
     if (!ret)
     {



More information about the vlc-commits mailing list