From 9f99f02eb21eb2e067b5f4b89e6349d65dcd7e39 Mon Sep 17 00:00:00 2001 From: attila Date: Wed, 9 Nov 2022 08:31:55 +0100 Subject: [PATCH] CoreAudioIODevice: Fix stale channel information after device information change Until this commit CoreAudioIODevice could report inconsistent information in its getActiveOutputChannels() and getOutputChannelNames() functions, and for inputs as well. The reason for this was that a sudden configuration change would immediately be reflected by the CoreAudioInternal::Stream::chanNames member because those are read in the Stream's constructor. The activeChan member would however just store stale values, until the Stream was recreated later during device reopen. This issue could lead to the AudioPluginHost crashing when opening a Bluetooth headset. --- .../native/juce_mac_CoreAudio.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/modules/juce_audio_devices/native/juce_mac_CoreAudio.cpp b/modules/juce_audio_devices/native/juce_mac_CoreAudio.cpp index be62e4395a..f3963f3c6e 100644 --- a/modules/juce_audio_devices/native/juce_mac_CoreAudio.cpp +++ b/modules/juce_audio_devices/native/juce_mac_CoreAudio.cpp @@ -622,12 +622,9 @@ public: stop (false); - const auto activeIns = BigInteger().setRange (0, jmin (ins .getHighestBit() + 1, getNumChannelNames (inStream)), true); - const auto activeOuts = BigInteger().setRange (0, jmin (outs.getHighestBit() + 1, getNumChannelNames (outStream)), true); - if (! setNominalSampleRate (newSampleRate)) { - updateDetailsFromDevice (activeIns, activeOuts); + updateDetailsFromDevice (ins, outs); error = "Couldn't change sample rate"; } else @@ -637,7 +634,7 @@ public: juceAudioObjectPropertyElementMain }, static_cast (bufferSizeSamples), err2log())) { - updateDetailsFromDevice (activeIns, activeOuts); + updateDetailsFromDevice (ins, outs); error = "Couldn't change buffer size"; } else @@ -646,7 +643,7 @@ public: // correctly report their new settings until some random time in the future, so // after calling updateDetailsFromDevice, we need to manually bodge these values // to make sure we're using the correct numbers.. - updateDetailsFromDevice (activeIns, activeOuts); + updateDetailsFromDevice (ins, outs); sampleRate = newSampleRate; bufferSize = bufferSizeSamples; @@ -837,13 +834,13 @@ public: //============================================================================== struct Stream { - Stream (bool isInput, CoreAudioInternal& parent, const BigInteger& active) + Stream (bool isInput, CoreAudioInternal& parent, const BigInteger& activeRequested) : input (isInput), latency (getLatencyFromDevice (isInput, parent)), bitDepth (getBitDepthFromDevice (isInput, parent)), - activeChans (active), chanNames (getChannelNames (isInput, parent)), - channelInfo (getChannelInfos (isInput, parent, active)), + activeChans (BigInteger().setRange (0, jmin (activeRequested.getHighestBit() + 1, chanNames.size()), true)), + channelInfo (getChannelInfos (isInput, parent, activeChans)), channels (static_cast (channelInfo.size())) {} @@ -984,8 +981,8 @@ public: const bool input; const int latency; const int bitDepth; - const BigInteger activeChans; const StringArray chanNames; + const BigInteger activeChans; const Array channelInfo; const int channels = 0; Float64 previousSampleTime;