diff --git a/src/core/audio/CrossfadeTransport.cpp b/src/core/audio/CrossfadeTransport.cpp index 00c0667c9..c45d5ce60 100644 --- a/src/core/audio/CrossfadeTransport.cpp +++ b/src/core/audio/CrossfadeTransport.cpp @@ -61,6 +61,7 @@ CrossfadeTransport::CrossfadeTransport() CrossfadeTransport::~CrossfadeTransport() { this->Stop(); + this->crossfader.Drain(); } PlaybackState CrossfadeTransport::GetPlaybackState() { @@ -93,9 +94,8 @@ void CrossfadeTransport::ReloadOutput() { void CrossfadeTransport::Stop() { { Lock lock(this->stateMutex); - this->crossfader.Stop(); - this->active.Stop(); - this->next.Stop(); + this->active.Reset(); + this->next.Reset(); } this->SetPlaybackState(PlaybackStopped); diff --git a/src/core/audio/Crossfader.cpp b/src/core/audio/Crossfader.cpp index 943dc9c24..6742f59e3 100644 --- a/src/core/audio/Crossfader.cpp +++ b/src/core/audio/Crossfader.cpp @@ -125,6 +125,18 @@ void Crossfader::Stop() { this->contextList.clear(); } +void Crossfader::Drain() { + LOCK(this->contextListLock); + + if (this->contextList.size()) { + for (FadeContextPtr context : this->contextList) { + context->direction = FadeOut; + } + + this->drainCondition.wait(lock); + } +} + void Crossfader::OnPlayerDestroying(Player* player) { if (player) { LOCK(this->contextListLock); @@ -269,6 +281,7 @@ void Crossfader::ProcessMessage(IMessage &message) { } else { this->Emptied(); + this->drainCondition.notify_all(); } } break; diff --git a/src/core/audio/Crossfader.h b/src/core/audio/Crossfader.h index ec3574176..1265aa55a 100644 --- a/src/core/audio/Crossfader.h +++ b/src/core/audio/Crossfader.h @@ -72,6 +72,7 @@ namespace musik { namespace core { namespace audio { void Pause(); void Resume(); void Stop(); + void Drain(); private: void ThreadLoop(); @@ -96,6 +97,7 @@ namespace musik { namespace core { namespace audio { musik::core::runtime::MessageQueue messageQueue; std::list contextList; std::atomic quit, paused; + std::condition_variable_any drainCondition; ITransport& transport; };