[vlc-commits] iOS audio unit: improve session handling for parallel playback instances
Felix Paul Kühne
git at videolan.org
Sat Jun 2 15:57:47 CEST 2018
vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Mon May 28 19:36:38 2018 +0200| [5a59782d4506183c944a8f027fd0d94767e65f7b] | 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
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5a59782d4506183c944a8f027fd0d94767e65f7b
---
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 db6e1224d8..a50be46c5f 100644
--- a/modules/audio_output/audiounit_ios.m
+++ b/modules/audio_output/audiounit_ios.m
@@ -71,6 +71,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
*****************************************************************************
@@ -293,9 +340,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