diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/qmmp/qmmpaudioengine.cpp | 2 | ||||
| -rw-r--r-- | src/qmmp/recycler.cpp | 22 | ||||
| -rw-r--r-- | src/qmmp/recycler.h | 5 |
3 files changed, 20 insertions, 9 deletions
diff --git a/src/qmmp/qmmpaudioengine.cpp b/src/qmmp/qmmpaudioengine.cpp index 618589ce9..79fc9cbd5 100644 --- a/src/qmmp/qmmpaudioengine.cpp +++ b/src/qmmp/qmmpaudioengine.cpp @@ -501,7 +501,7 @@ void QmmpAudioEngine::flush(bool final) break; } - while ((!m_done && !m_finish) && m_output->recycler()->full()) + while ((m_output->recycler()->full() || m_output->recycler()->blocked()) && (!m_done && !m_finish)) { mutex()->unlock(); m_output->recycler()->cond()->wait(m_output->recycler()->mutex()); diff --git a/src/qmmp/recycler.cpp b/src/qmmp/recycler.cpp index 4ac0cb640..299d30840 100644 --- a/src/qmmp/recycler.cpp +++ b/src/qmmp/recycler.cpp @@ -22,6 +22,7 @@ Recycler::Recycler (unsigned int sz) { buffers[i] = new Buffer; } + m_blocked = 0; } @@ -32,8 +33,8 @@ Recycler::~Recycler() delete buffers[i]; buffers[i] = 0; } - delete [] buffers; + m_blocked = 0; } @@ -42,6 +43,11 @@ bool Recycler::full() const return current_count == buffer_count; } +bool Recycler::blocked() +{ + return buffers[add_index] == m_blocked; +} + bool Recycler::empty() const { @@ -74,25 +80,26 @@ void Recycler::add() current_count++; } - Buffer *Recycler::next() { - return !current_count ? 0 : buffers[done_index]; + if(current_count) + { + m_blocked = buffers[done_index]; + return m_blocked; + } + return 0; } - void Recycler::done() { - //done_index = ++done_index % buffer_count; + m_blocked = 0; if (current_count) { current_count--; done_index = ++done_index % buffer_count; } - //scurrent_count--; } - void Recycler::clear() { current_count = 0; @@ -100,7 +107,6 @@ void Recycler::clear() done_index = 0; } - unsigned int Recycler::size() const { return buffer_count * QMMP_BLOCK_SIZE; diff --git a/src/qmmp/recycler.h b/src/qmmp/recycler.h index 82dcb30a9..a52e37143 100644 --- a/src/qmmp/recycler.h +++ b/src/qmmp/recycler.h @@ -81,12 +81,17 @@ public: { return &cnd; } + /*! + * Returns \b true if the next buffer is used by output. Otherwise returns \b false. + */ + bool blocked(); private: unsigned int buffer_count, add_index, done_index, current_count; Buffer **buffers; QMutex mtx; QWaitCondition cnd; + Buffer *m_blocked; }; #endif // __recycler_h |
