Fix race condition by adding required locking in WasapiOut to avoid rare

crash.
This commit is contained in:
casey langen 2021-12-27 22:41:57 -08:00
parent 6bae859ac2
commit 4bb9bbad3c
2 changed files with 10 additions and 0 deletions

View File

@ -1,3 +1,7 @@
0.96.10
* fixed race condition in WasapiOut that caused the app to crash.
0.96.9
* fixed `-rpath` to use `$ORIGIN` instead of `./` to appease `Feodra 35`.

View File

@ -359,6 +359,8 @@ OutputState WasapiOut::Play(IBuffer *buffer, IBufferProvider *provider) {
}
void WasapiOut::Reset() {
Lock lock(this->stateMutex);
if (this->simpleAudioVolume) {
this->simpleAudioVolume->Release();
}
@ -516,6 +518,7 @@ found_or_done:
int WasapiOut::GetDefaultSampleRate() {
int result = -1;
Lock lock(this->stateMutex);
this->InitializeAudioClient();
if (this->audioClient) {
WAVEFORMATEX* deviceFormat = nullptr;
@ -529,6 +532,8 @@ int WasapiOut::GetDefaultSampleRate() {
}
bool WasapiOut::InitializeAudioClient() {
/* assumes stateMutex is locked */
CoInitializeEx(nullptr, COINIT_MULTITHREADED);
HRESULT result = S_FALSE;
@ -584,6 +589,7 @@ bool WasapiOut::InitializeAudioClient() {
}
bool WasapiOut::Configure(IBuffer *buffer) {
/* assumes stateMutex is locked */
if (this->audioClient &&
waveFormat.Format.nChannels == buffer->Channels() &&
waveFormat.Format.nSamplesPerSec == buffer->SampleRate())