From fbef0349036292f94902d0c3102a7418cfa6f9a9 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Sat, 15 Jan 2022 02:09:26 -0800 Subject: [PATCH] Cog Audio: Further overhaul output buffering and track queue code --- Audio/AudioPlayer.h | 3 +- Audio/AudioPlayer.m | 10 ++++-- Audio/Chain/ConverterNode.m | 18 ++++++++++ Audio/Chain/OutputNode.h | 3 +- Audio/Chain/OutputNode.m | 5 ++- Audio/Chain/RefillNode.m | 22 ++++++++++-- Audio/Output/OutputCoreAudio.h | 4 +++ Audio/Output/OutputCoreAudio.m | 63 +++++++++++++++++++++------------- 8 files changed, 93 insertions(+), 35 deletions(-) diff --git a/Audio/AudioPlayer.h b/Audio/AudioPlayer.h index 10aa16249..545888103 100644 --- a/Audio/AudioPlayer.h +++ b/Audio/AudioPlayer.h @@ -95,9 +95,10 @@ //- (BufferChain *)bufferChain; - (void)launchOutputThread; - (void)endOfInputPlayed; -- (void)endOfInputPlayedOut; - (void)sendDelegateMethod:(SEL)selector withObject:(id)obj waitUntilDone:(BOOL)wait; - (void)sendDelegateMethod:(SEL)selector withObject:(id)obj withObject:(id)obj2 waitUntilDone:(BOOL)wait; + +- (BOOL)chainQueueHasTracks; @end @protocol AudioPlayerDelegate diff --git a/Audio/AudioPlayer.m b/Audio/AudioPlayer.m index 2d057cd65..33cf8f847 100644 --- a/Audio/AudioPlayer.m +++ b/Audio/AudioPlayer.m @@ -261,7 +261,7 @@ - (void)notifyStreamChanged:(id)userInfo { - [self sendDelegateMethod:@selector(audioPlayer:didBeginStream:) withObject:userInfo waitUntilDone:NO]; + [self sendDelegateMethod:@selector(audioPlayer:didBeginStream:) withObject:userInfo waitUntilDone:YES]; } - (void)addChainToQueue:(BufferChain *)newChain @@ -446,12 +446,16 @@ [semaphore signal]; } + [self notifyStreamChanged:[bufferChain userInfo]]; [output setEndOfStream:NO]; } -- (void)endOfInputPlayedOut +- (BOOL)chainQueueHasTracks { - [self notifyStreamChanged:[bufferChain userInfo]]; + @synchronized (chainQueue) { + return [chainQueue count] > 0; + } + return NO; } - (void)sendDelegateMethod:(SEL)selector withObject:(id)obj waitUntilDone:(BOOL)wait diff --git a/Audio/Chain/ConverterNode.m b/Audio/Chain/ConverterNode.m index bbe28e592..4352e1415 100644 --- a/Audio/Chain/ConverterNode.m +++ b/Audio/Chain/ConverterNode.m @@ -8,6 +8,9 @@ #import "ConverterNode.h" +#import "BufferChain.h" +#import "OutputNode.h" + #import "Logging.h" #import