Prevent CoreAudio driver failing on finish if Dummy driver was selected

This commit is contained in:
Marcelo Fernandez 2018-08-25 10:42:30 -03:00
parent 12290c172a
commit 5d0622a8de

View file

@ -331,55 +331,57 @@ bool AudioDriverCoreAudio::try_lock() {
} }
void AudioDriverCoreAudio::finish() { void AudioDriverCoreAudio::finish() {
OSStatus result; if (audio_unit) {
OSStatus result;
lock(); lock();
AURenderCallbackStruct callback; AURenderCallbackStruct callback;
zeromem(&callback, sizeof(AURenderCallbackStruct)); zeromem(&callback, sizeof(AURenderCallbackStruct));
result = AudioUnitSetProperty(audio_unit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, kOutputBus, &callback, sizeof(callback)); result = AudioUnitSetProperty(audio_unit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, kOutputBus, &callback, sizeof(callback));
if (result != noErr) {
ERR_PRINT("AudioUnitSetProperty failed");
}
if (active) {
result = AudioOutputUnitStop(audio_unit);
if (result != noErr) { if (result != noErr) {
ERR_PRINT("AudioOutputUnitStop failed"); ERR_PRINT("AudioUnitSetProperty failed");
} }
active = false; if (active) {
} result = AudioOutputUnitStop(audio_unit);
if (result != noErr) {
ERR_PRINT("AudioOutputUnitStop failed");
}
result = AudioUnitUninitialize(audio_unit); active = false;
if (result != noErr) { }
ERR_PRINT("AudioUnitUninitialize failed");
} result = AudioUnitUninitialize(audio_unit);
if (result != noErr) {
ERR_PRINT("AudioUnitUninitialize failed");
}
#ifdef OSX_ENABLED #ifdef OSX_ENABLED
AudioObjectPropertyAddress prop; AudioObjectPropertyAddress prop;
prop.mSelector = kAudioHardwarePropertyDefaultOutputDevice; prop.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
prop.mScope = kAudioObjectPropertyScopeGlobal; prop.mScope = kAudioObjectPropertyScopeGlobal;
prop.mElement = kAudioObjectPropertyElementMaster; prop.mElement = kAudioObjectPropertyElementMaster;
result = AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &prop, &output_device_address_cb, this); result = AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &prop, &output_device_address_cb, this);
if (result != noErr) { if (result != noErr) {
ERR_PRINT("AudioObjectRemovePropertyListener failed"); ERR_PRINT("AudioObjectRemovePropertyListener failed");
} }
#endif #endif
result = AudioComponentInstanceDispose(audio_unit); result = AudioComponentInstanceDispose(audio_unit);
if (result != noErr) { if (result != noErr) {
ERR_PRINT("AudioComponentInstanceDispose failed"); ERR_PRINT("AudioComponentInstanceDispose failed");
} }
unlock(); unlock();
}
if (mutex) { if (mutex) {
memdelete(mutex); memdelete(mutex);
mutex = NULL; mutex = NULL;
} }
}; }
Error AudioDriverCoreAudio::capture_start() { Error AudioDriverCoreAudio::capture_start() {
@ -576,6 +578,7 @@ String AudioDriverCoreAudio::capture_get_device() {
#endif #endif
AudioDriverCoreAudio::AudioDriverCoreAudio() { AudioDriverCoreAudio::AudioDriverCoreAudio() {
audio_unit = NULL;
active = false; active = false;
mutex = NULL; mutex = NULL;