From c74a56f3b961fe787c9a03d7bdb0821525319c33 Mon Sep 17 00:00:00 2001 From: Nimetu Date: Sat, 20 Oct 2018 19:07:32 +0300 Subject: [PATCH] Fixed: Streaming source did not report finished state correctly --HG-- branch : develop --- code/nel/include/nel/sound/stream_file_source.h | 3 ++- code/nel/src/sound/stream_file_source.cpp | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/code/nel/include/nel/sound/stream_file_source.h b/code/nel/include/nel/sound/stream_file_source.h index 79151f171..b7c48f96a 100644 --- a/code/nel/include/nel/sound/stream_file_source.h +++ b/code/nel/include/nel/sound/stream_file_source.h @@ -98,8 +98,9 @@ private: NLMISC::IThread *m_Thread; IAudioDecoder *m_AudioDecoder; - + bool m_Paused; + bool m_DecodingEnded; }; /* class CStreamFileSource */ diff --git a/code/nel/src/sound/stream_file_source.cpp b/code/nel/src/sound/stream_file_source.cpp index 185b7514f..9a03ba2d8 100644 --- a/code/nel/src/sound/stream_file_source.cpp +++ b/code/nel/src/sound/stream_file_source.cpp @@ -45,7 +45,7 @@ using namespace std; namespace NLSOUND { CStreamFileSource::CStreamFileSource(CStreamFileSound *streamFileSound, bool spawn, TSpawnEndCallback cb, void *cbUserParam, NL3D::CCluster *cluster, CGroupController *groupController) -: CStreamSource(streamFileSound, spawn, cb, cbUserParam, cluster, groupController), m_AudioDecoder(NULL), m_Paused(false) +: CStreamSource(streamFileSound, spawn, cb, cbUserParam, cluster, groupController), m_AudioDecoder(NULL), m_Paused(false), m_DecodingEnded(false) { m_Thread = NLMISC::IThread::create(this); } @@ -244,7 +244,7 @@ void CStreamFileSource::resume() bool CStreamFileSource::isEnded() { - return (!m_Thread->isRunning() && !_Playing && !m_WaitingForPlay && !m_Paused); + return m_DecodingEnded || (!m_Thread->isRunning() && !_Playing && !m_WaitingForPlay && !m_Paused); } float CStreamFileSource::getLength() @@ -319,6 +319,7 @@ void CStreamFileSource::run() this->getRecommendedBufferSize(samples, bytes); uint32 recSleep = 40; uint32 doSleep = 10; + m_DecodingEnded = false; while (_Playing || m_WaitingForPlay) { if (!m_AudioDecoder->isMusicEnded()) @@ -369,6 +370,9 @@ void CStreamFileSource::run() { delete m_AudioDecoder; m_AudioDecoder = NULL; + // _Playing cannot be used to detect play state because its required in cleanup + // Using m_AudioDecoder in isEnded() may result race condition (decoder is only created after thread is started) + m_DecodingEnded = true; } // drop buffers m_FreeBuffers = 3;