[Core Audio Output] Improve safety on stopping
Synchronize audio setup and audio stopping on the object's own pointer, to hopefully prevent race conditions with out of sync calls to the stop function from both the main and the audio thread. Signed-off-by: Christopher Snowhill <kode54@gmail.com>swiftingly
parent
e9230a080c
commit
0997ca2c93
|
@ -344,7 +344,6 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
||||||
}
|
}
|
||||||
|
|
||||||
stopped = YES;
|
stopped = YES;
|
||||||
if(!stopInvoked)
|
|
||||||
[self stop];
|
[self stop];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -623,7 +622,9 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
||||||
if(_au)
|
if(_au)
|
||||||
[self stop];
|
[self stop];
|
||||||
|
|
||||||
|
@synchronized(self) {
|
||||||
stopInvoked = NO;
|
stopInvoked = NO;
|
||||||
|
|
||||||
running = NO;
|
running = NO;
|
||||||
stopping = NO;
|
stopping = NO;
|
||||||
stopped = NO;
|
stopped = NO;
|
||||||
|
@ -787,6 +788,7 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
||||||
observersapplied = YES;
|
observersapplied = YES;
|
||||||
|
|
||||||
return (err == nil);
|
return (err == nil);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setVolume:(double)v {
|
- (void)setVolume:(double)v {
|
||||||
|
@ -810,6 +812,8 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)stop {
|
- (void)stop {
|
||||||
|
@synchronized(self) {
|
||||||
|
if(stopInvoked) return;
|
||||||
stopInvoked = YES;
|
stopInvoked = YES;
|
||||||
if(observersapplied) {
|
if(observersapplied) {
|
||||||
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.outputDevice" context:kOutputCoreAudioContext];
|
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.outputDevice" context:kOutputCoreAudioContext];
|
||||||
|
@ -852,12 +856,13 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
||||||
[_au stopHardware];
|
[_au stopHardware];
|
||||||
_au = nil;
|
_au = nil;
|
||||||
}
|
}
|
||||||
if(running)
|
if(running) {
|
||||||
while(!stopped) {
|
while(!stopped) {
|
||||||
stopping = YES;
|
stopping = YES;
|
||||||
[readSemaphore signal];
|
[readSemaphore signal];
|
||||||
[writeSemaphore timedWait:5000];
|
[writeSemaphore timedWait:5000];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if(_eq) {
|
if(_eq) {
|
||||||
[outputController endEqualizer:_eq];
|
[outputController endEqualizer:_eq];
|
||||||
if(eqInitialized) {
|
if(eqInitialized) {
|
||||||
|
@ -881,10 +886,10 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const
|
||||||
#endif
|
#endif
|
||||||
outputController = nil;
|
outputController = nil;
|
||||||
visController = nil;
|
visController = nil;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
if(!stopInvoked)
|
|
||||||
[self stop];
|
[self stop];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue