From 44b813d2bf0df95892e17c692e8f96dbfba2e10b Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Sat, 11 Dec 2021 00:22:54 -0800 Subject: [PATCH] Audio queue: Better handle queues of lots of short files --- Audio/AudioPlayer.m | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/Audio/AudioPlayer.m b/Audio/AudioPlayer.m index 4567427cd..aeb9b9408 100644 --- a/Audio/AudioPlayer.m +++ b/Audio/AudioPlayer.m @@ -236,6 +236,8 @@ - (BOOL)endOfInputReached:(BufferChain *)sender //Sender is a BufferChain { + unsigned long queueCount = 0; + @synchronized (chainQueue) { // No point in constructing new chain for the next playlist entry // if there's already one at the head of chainQueue... r-r-right? @@ -247,11 +249,24 @@ } } - if ([chainQueue count] >= 5) - { - return YES; - } + // We don't want to do this, it may happen with a lot of short files + //if ([chainQueue count] >= 5) + //{ + // return YES; + //} + queueCount = [chainQueue count]; + } + + while (queueCount >= 5) + { + usleep(2000); + @synchronized (chainQueue) { + queueCount = [chainQueue count]; + } + } + + @synchronized (chainQueue) { BufferChain *newChain = nil; nextStreamUserInfo = [sender userInfo];