Fixed a bug that could result in Player threads being unable to terminate.

This commit is contained in:
Casey Langen 2016-06-13 00:43:14 -07:00
parent deddc410a0
commit c6610585b7

View File

@ -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);