From c6610585b7c9a28ca82893bb78e93526416daf59 Mon Sep 17 00:00:00 2001 From: Casey Langen Date: Mon, 13 Jun 2016 00:43:14 -0700 Subject: [PATCH] Fixed a bug that could result in Player threads being unable to terminate. --- src/core/audio/Player.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/core/audio/Player.cpp b/src/core/audio/Player.cpp index de7878476..826bb642e 100644 --- a/src/core/audio/Player.cpp +++ b/src/core/audio/Player.cpp @@ -127,6 +127,8 @@ void Player::ThreadLoop() { /* create and open the stream */ this->stream = Stream::Create(); + BufferPtr buffer; + if (this->stream->OpenStream(this->url)) { /* precache until buffers are full */ bool keepPrecaching = true; @@ -146,7 +148,6 @@ void Player::ThreadLoop() { /* we're ready to go.... */ bool finished = false; - BufferPtr buffer; while (!finished && !this->Exited()) { /* see if we've been asked to seek since the last sample was @@ -166,7 +167,7 @@ void Player::ThreadLoop() { /* if we've allocated a buffer, but it hasn't been written to the output yet, unlock it. this is an important step, and if - not performed, will result in a deadlock just below while + not performed, will result in a deadlock just below while waiting for all buffers to complete. */ if (buffer) { this->OnBufferProcessed(buffer.get()); @@ -252,6 +253,12 @@ void Player::ThreadLoop() { this->state = Player::Quit; + /* unlock any remaining buffers... see comment above */ + if (buffer) { + this->OnBufferProcessed(buffer.get()); + buffer.reset(); + } + /* wait until all remaining buffers have been written, set final state... */ { boost::mutex::scoped_lock lock(this->queueMutex);