Fixed: Streaming source did not report finished state correctly

--HG--
branch : develop
This commit is contained in:
Nimetu 2018-10-20 19:07:32 +03:00
parent 12ec528b5a
commit c74a56f3b9
2 changed files with 8 additions and 3 deletions

View file

@ -100,6 +100,7 @@ private:
IAudioDecoder *m_AudioDecoder; IAudioDecoder *m_AudioDecoder;
bool m_Paused; bool m_Paused;
bool m_DecodingEnded;
}; /* class CStreamFileSource */ }; /* class CStreamFileSource */

View file

@ -45,7 +45,7 @@ using namespace std;
namespace NLSOUND { namespace NLSOUND {
CStreamFileSource::CStreamFileSource(CStreamFileSound *streamFileSound, bool spawn, TSpawnEndCallback cb, void *cbUserParam, NL3D::CCluster *cluster, CGroupController *groupController) 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); m_Thread = NLMISC::IThread::create(this);
} }
@ -244,7 +244,7 @@ void CStreamFileSource::resume()
bool CStreamFileSource::isEnded() 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() float CStreamFileSource::getLength()
@ -319,6 +319,7 @@ void CStreamFileSource::run()
this->getRecommendedBufferSize(samples, bytes); this->getRecommendedBufferSize(samples, bytes);
uint32 recSleep = 40; uint32 recSleep = 40;
uint32 doSleep = 10; uint32 doSleep = 10;
m_DecodingEnded = false;
while (_Playing || m_WaitingForPlay) while (_Playing || m_WaitingForPlay)
{ {
if (!m_AudioDecoder->isMusicEnded()) if (!m_AudioDecoder->isMusicEnded())
@ -369,6 +370,9 @@ void CStreamFileSource::run()
{ {
delete m_AudioDecoder; delete m_AudioDecoder;
m_AudioDecoder = NULL; 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 // drop buffers
m_FreeBuffers = 3; m_FreeBuffers = 3;