aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2010-01-29 11:23:57 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2010-01-29 11:23:57 +0000
commit9f419df28c3ccc492add0c3d7355c3451c008491 (patch)
treee0ceba7bc7ed7a346e010e415643642f882f1292 /src
parent855bc81c09b6a73e026e187a3caf7d71fa0fb7dc (diff)
downloadqmmp-9f419df28c3ccc492add0c3d7355c3451c008491.tar.gz
qmmp-9f419df28c3ccc492add0c3d7355c3451c008491.tar.bz2
qmmp-9f419df28c3ccc492add0c3d7355c3451c008491.zip
fixed some problems with buffers
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@1532 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src')
-rw-r--r--src/qmmp/qmmpaudioengine.cpp2
-rw-r--r--src/qmmp/recycler.cpp22
-rw-r--r--src/qmmp/recycler.h5
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