Browse Source

Fixed a assertion/crash when a macOS CoreAudio device becomes unavailable during playback

tags/2021-05-28
hogliux 8 years ago
parent
commit
728e2dbe82
1 changed files with 24 additions and 30 deletions
  1. +24
    -30
      modules/juce_audio_devices/native/juce_mac_CoreAudio.cpp

+ 24
- 30
modules/juce_audio_devices/native/juce_mac_CoreAudio.cpp View File

@@ -1366,21 +1366,7 @@ public:
}
}
void stop() override
{
AudioIODeviceCallback* lastCallback = nullptr;
{
const ScopedLock sl (callbackLock);
std::swap (callback, lastCallback);
}
for (int i = 0; i < devices.size(); ++i)
devices.getUnchecked(i)->device->stop();
if (lastCallback != nullptr)
lastCallback->audioDeviceStopped();
}
void stop() override { shutdown ({}); }
String getLastError() override
{
@@ -1456,6 +1442,27 @@ private:
}
}
void shutdown (const String& error)
{
AudioIODeviceCallback* lastCallback = nullptr;
{
const ScopedLock sl (callbackLock);
std::swap (callback, lastCallback);
}
for (int i = 0; i < devices.size(); ++i)
devices.getUnchecked(i)->device->stop();
if (lastCallback != nullptr)
{
if (error.isNotEmpty())
lastCallback->audioDeviceError (error);
else
lastCallback->audioDeviceStopped();
}
}
void reset()
{
for (int i = 0; i < devices.size(); ++i)
@@ -1584,21 +1591,8 @@ private:
callback->audioDeviceAboutToStart (device);
}
void handleAudioDeviceStopped()
{
const ScopedLock sl (callbackLock);
if (callback != nullptr)
callback->audioDeviceStopped();
}
void handleAudioDeviceError (const String& errorMessage)
{
const ScopedLock sl (callbackLock);
if (callback != nullptr)
callback->audioDeviceError (errorMessage);
}
void handleAudioDeviceStopped() { shutdown ({}); }
void handleAudioDeviceError (const String& errorMessage) { shutdown (errorMessage.isNotEmpty() ? errorMessage : String ("unknown")); }
//==============================================================================
struct DeviceWrapper : private AudioIODeviceCallback


Loading…
Cancel
Save