diff --git a/Audio/Chain/OutputNode.m b/Audio/Chain/OutputNode.m index 577a3398d..9f3903577 100644 --- a/Audio/Chain/OutputNode.m +++ b/Audio/Chain/OutputNode.m @@ -176,4 +176,5 @@ - (void)sustainHDCD { [output sustainHDCD]; } + @end diff --git a/Audio/Output/OutputCoreAudio.h b/Audio/Output/OutputCoreAudio.h index 943e88c8d..0942d41d2 100644 --- a/Audio/Output/OutputCoreAudio.h +++ b/Audio/Output/OutputCoreAudio.h @@ -38,6 +38,7 @@ BOOL stopped; BOOL started; BOOL paused; + BOOL stopNext; BOOL eqEnabled; diff --git a/Audio/Output/OutputCoreAudio.m b/Audio/Output/OutputCoreAudio.m index a8f0fe533..ae9627ef1 100644 --- a/Audio/Output/OutputCoreAudio.m +++ b/Audio/Output/OutputCoreAudio.m @@ -160,6 +160,7 @@ - (id)initWithController:(OutputNode *)c listenerapplied = NO; running = NO; started = NO; + stopNext = NO; atomic_init(&bytesRendered, 0); atomic_init(&bytesHdcdSustained, 0); @@ -210,6 +211,7 @@ - (void)threadEntry:(id)arg { running = YES; started = NO; + stopNext = NO; size_t eventCount = 0; atomic_store(&bytesRendered, 0); NSMutableArray *delayedEvents = [[NSMutableArray alloc] init]; @@ -277,6 +279,10 @@ - (void)threadEntry:(id)arg else bytesBuffered -= CHUNK_SIZE; } + else { + stopNext = YES; + break; + } [delayedEvents addObject:[NSNumber numberWithLong:bytesBuffered]]; delayedEventsPopped = NO; if (!started) { @@ -554,6 +560,7 @@ - (BOOL)setup stopping = NO; stopped = NO; paused = NO; + stopNext = NO; outputDeviceID = -1; AudioComponentDescription desc; @@ -722,6 +729,14 @@ - (void)start - (void)stop { + if (stopNext && started && !paused) { + while (![[outputController buffer] isEmpty]) + usleep(500); + } + if (stopNext) { + stopNext = NO; + [self signalEndOfStream]; + } stopInvoked = YES; stopping = YES; paused = NO;