1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

CoreAudio: Prevent racing between calls to start and stop a device

This commit is contained in:
Anthony Nicholls 2024-06-07 17:05:44 +01:00 committed by Tom Poole
parent 2516ad808e
commit 4808fdce30

View file

@ -1051,7 +1051,7 @@ public:
CoreAudioIODevice& owner;
int bitDepth = 32;
int xruns = 0;
std::atomic<int> xruns = 0;
Array<double> sampleRates;
Array<int> bufferSizes;
AudioDeviceID deviceID;
@ -1159,7 +1159,7 @@ private:
return x.mSelector == kAudioDeviceProcessorOverload;
});
intern.xruns += xruns;
intern.xruns += (int) xruns;
const auto detailsChanged = std::any_of (pa, pa + numAddresses, [] (const AudioObjectPropertyAddress& x)
{
@ -1325,6 +1325,8 @@ public:
void start (AudioIODeviceCallback* callback) override
{
const ScopedLock sl (startStopLock);
if (internal->start (callback))
pendingCallback = nullptr;
}
@ -1332,12 +1334,14 @@ public:
void stop() override
{
stopAndGetLastCallback();
const ScopedLock sl (startStopLock);
pendingCallback = nullptr;
}
void stopWithPendingCallback()
{
const ScopedLock sl (closeLock);
const ScopedLock sl (startStopLock);
if (pendingCallback == nullptr)
pendingCallback = stopAndGetLastCallback();
@ -1399,7 +1403,7 @@ private:
AudioIODeviceCallback* pendingCallback = nullptr;
AsyncRestarter* restarter = nullptr;
BigInteger inputChannelsRequested, outputChannelsRequested;
CriticalSection closeLock;
CriticalSection startStopLock;
AudioIODeviceCallback* stopAndGetLastCallback() const
{
@ -1424,6 +1428,7 @@ private:
getCurrentSampleRate(),
getCurrentBufferSizeSamples());
const ScopedLock sl { startStopLock };
start (pendingCallback);
}