Audio player: Attempt to fix queue issues. There are still remaining issues if a single short track queues repeatedly and the user changes tracks manually.
This commit is contained in:
parent
38c530043d
commit
476dd913b2
2 changed files with 37 additions and 75 deletions
|
@ -17,9 +17,6 @@
|
||||||
BufferChain *bufferChain;
|
BufferChain *bufferChain;
|
||||||
OutputNode *output;
|
OutputNode *output;
|
||||||
|
|
||||||
BOOL stoppingReQueue;
|
|
||||||
NSOperationQueue *reQueue;
|
|
||||||
|
|
||||||
double volume;
|
double volume;
|
||||||
|
|
||||||
NSMutableArray *chainQueue;
|
NSMutableArray *chainQueue;
|
||||||
|
|
|
@ -28,22 +28,12 @@
|
||||||
outputLaunched = NO;
|
outputLaunched = NO;
|
||||||
endOfInputReached = NO;
|
endOfInputReached = NO;
|
||||||
|
|
||||||
stoppingReQueue = NO;
|
|
||||||
reQueue = [[NSOperationQueue alloc] init];
|
|
||||||
[reQueue setMaxConcurrentOperationCount:1];
|
|
||||||
|
|
||||||
chainQueue = [[NSMutableArray alloc] init];
|
chainQueue = [[NSMutableArray alloc] init];
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc
|
|
||||||
{
|
|
||||||
stoppingReQueue = YES;
|
|
||||||
[reQueue waitUntilAllOperationsAreFinished];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setDelegate:(id)d
|
- (void)setDelegate:(id)d
|
||||||
{
|
{
|
||||||
delegate = d;
|
delegate = d;
|
||||||
|
@ -217,8 +207,6 @@
|
||||||
- (void)stop
|
- (void)stop
|
||||||
{
|
{
|
||||||
//Set shouldoContinue to NO on all things
|
//Set shouldoContinue to NO on all things
|
||||||
stoppingReQueue = YES;
|
|
||||||
[reQueue waitUntilAllOperationsAreFinished];
|
|
||||||
[self setShouldContinue:NO];
|
[self setShouldContinue:NO];
|
||||||
[self setPlaybackStatus:CogStatusStopped waitUntilDone:YES];
|
[self setPlaybackStatus:CogStatusStopped waitUntilDone:YES];
|
||||||
}
|
}
|
||||||
|
@ -294,8 +282,6 @@
|
||||||
[anObject setShouldContinue:NO];
|
[anObject setShouldContinue:NO];
|
||||||
}
|
}
|
||||||
[chainQueue removeAllObjects];
|
[chainQueue removeAllObjects];
|
||||||
stoppingReQueue = YES;
|
|
||||||
[reQueue waitUntilAllOperationsAreFinished];
|
|
||||||
|
|
||||||
if (endOfInputReached) {
|
if (endOfInputReached) {
|
||||||
[self endOfInputReached:bufferChain];
|
[self endOfInputReached:bufferChain];
|
||||||
|
@ -344,49 +330,34 @@
|
||||||
[newChain setShouldContinue:YES];
|
[newChain setShouldContinue:YES];
|
||||||
[newChain launchThreads];
|
[newChain launchThreads];
|
||||||
|
|
||||||
stoppingReQueue = NO;
|
|
||||||
|
|
||||||
if (([chainQueue count] + [reQueue operationCount]) >= 5) {
|
|
||||||
NSBlockOperation *op = [[NSBlockOperation alloc] init];
|
|
||||||
|
|
||||||
[op addExecutionBlock:^{
|
|
||||||
unsigned long queueCount;
|
|
||||||
|
|
||||||
if (self->stoppingReQueue) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
@synchronized (self->chainQueue) {
|
|
||||||
queueCount = [self->chainQueue count];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (queueCount < 5) {
|
|
||||||
@synchronized (self->chainQueue) {
|
|
||||||
[self->chainQueue insertObject:newChain atIndex:[self->chainQueue count]];
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self->stoppingReQueue) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
usleep(5000);
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
|
|
||||||
[reQueue addOperation:op];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
[chainQueue insertObject:newChain atIndex:[chainQueue count]];
|
[chainQueue insertObject:newChain atIndex:[chainQueue count]];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)endOfInputReached:(BufferChain *)sender //Sender is a BufferChain
|
- (BOOL)endOfInputReached:(BufferChain *)sender //Sender is a BufferChain
|
||||||
{
|
{
|
||||||
unsigned long queueCount = 0;
|
// Stop single or series of short tracks from queueing forever
|
||||||
|
{
|
||||||
|
unsigned long queueCount;
|
||||||
|
|
||||||
|
@synchronized (chainQueue) {
|
||||||
|
queueCount = [chainQueue count];
|
||||||
|
}
|
||||||
|
|
||||||
|
while (queueCount >= 5)
|
||||||
|
{
|
||||||
|
usleep(10000);
|
||||||
|
@synchronized (chainQueue) {
|
||||||
|
queueCount = [chainQueue count];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [self endOfInputReachedInternal:sender];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)endOfInputReachedInternal:(BufferChain *)sender //Sender is a BufferChain
|
||||||
|
{
|
||||||
|
BufferChain *newChain = nil;
|
||||||
|
|
||||||
@synchronized (chainQueue) {
|
@synchronized (chainQueue) {
|
||||||
// No point in constructing new chain for the next playlist entry
|
// No point in constructing new chain for the next playlist entry
|
||||||
|
@ -399,32 +370,24 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
queueCount = [chainQueue count] + [reQueue operationCount];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (queueCount >= 5)
|
|
||||||
{
|
|
||||||
[reQueue waitUntilAllOperationsAreFinished];
|
|
||||||
}
|
|
||||||
|
|
||||||
@synchronized (chainQueue) {
|
|
||||||
// We don't want to do this, it may happen with a lot of short files
|
// We don't want to do this, it may happen with a lot of short files
|
||||||
//if ([chainQueue count] >= 5)
|
//if ([chainQueue count] >= 5)
|
||||||
//{
|
//{
|
||||||
// return YES;
|
// return YES;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
BufferChain *newChain = nil;
|
|
||||||
|
|
||||||
nextStreamUserInfo = [sender userInfo];
|
nextStreamUserInfo = [sender userInfo];
|
||||||
|
|
||||||
nextStreamRGInfo = [sender rgInfo];
|
nextStreamRGInfo = [sender rgInfo];
|
||||||
|
}
|
||||||
|
|
||||||
|
// This call can sometimes lead to invoking a chainQueue block on another thread
|
||||||
[self requestNextStream: nextStreamUserInfo];
|
[self requestNextStream: nextStreamUserInfo];
|
||||||
|
|
||||||
if (!nextStream)
|
if (!nextStream)
|
||||||
return YES;
|
return YES;
|
||||||
|
|
||||||
|
@synchronized (chainQueue) {
|
||||||
newChain = [[BufferChain alloc] initWithController:self];
|
newChain = [[BufferChain alloc] initWithController:self];
|
||||||
|
|
||||||
endOfInputReached = YES;
|
endOfInputReached = YES;
|
||||||
|
@ -435,7 +398,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([[nextStream scheme] isEqualToString:[[lastChain streamURL] scheme]]
|
if ([[nextStream scheme] isEqualToString:[[lastChain streamURL] scheme]]
|
||||||
&& [[nextStream host] isEqualToString:[[lastChain streamURL] host]]
|
&& (([nextStream host] == nil &&
|
||||||
|
[[lastChain streamURL] host] == nil)
|
||||||
|
|| [[nextStream host] isEqualToString:[[lastChain streamURL] host]])
|
||||||
&& [[nextStream path] isEqualToString:[[lastChain streamURL] path]])
|
&& [[nextStream path] isEqualToString:[[lastChain streamURL] path]])
|
||||||
{
|
{
|
||||||
if ([lastChain setTrack:nextStream]
|
if ([lastChain setTrack:nextStream]
|
||||||
|
|
Loading…
Reference in a new issue