diff options
author | Luo Jinghua <sunmoon1997@gmail.com> | 2012-12-21 15:03:17 +0800 |
---|---|---|
committer | Luo Jinghua <sunmoon1997@gmail.com> | 2012-12-21 15:03:17 +0800 |
commit | 1626408838eb480cbb53c8789711d7cdc56b495c (patch) | |
tree | 1b305d9643662d4c711695352920c476f083f0fe /src | |
parent | ed4e499dca1e636df9b3815e6478730189d31a4c (diff) |
if no buffer is queued, then wait for one
Diffstat (limited to 'src')
-rw-r--r-- | src/device_mixer.cpp | 21 | ||||
-rw-r--r-- | src/device_mixer.h | 2 |
2 files changed, 18 insertions, 5 deletions
diff --git a/src/device_mixer.cpp b/src/device_mixer.cpp index ed10ab5..0a446c2 100644 --- a/src/device_mixer.cpp +++ b/src/device_mixer.cpp @@ -348,7 +348,7 @@ namespace audiere { return 0; while (m_free_list.empty()) { - m_buffer_cond.wait(m_buffer_mutex, 10); + m_buffer_cond.wait(m_buffer_mutex, 1); if (m_shutdown) return 0; } @@ -376,23 +376,35 @@ namespace audiere { if (m_shutdown) return false; + bool donotify = m_queue.empty(); while (m_queue.size() >= size_t(m_max_queue_len)) { - m_cond.wait(m_mutex, 10); + m_cond.wait(m_mutex, 1); if (m_shutdown) return false; } m_queue.push_back(buffer); + if (donotify) + m_cond.notify(); return true; } - AudioBuffer* AudioQueue::pop() + AudioBuffer* AudioQueue::pop(bool wait) { SYNCHRONIZED(m_mutex); - if (m_shutdown || m_queue.empty()) + if (m_shutdown) + return 0; + + if (!wait && m_queue.empty()) return 0; + while (m_queue.empty()) { + m_cond.wait(m_mutex, 1); + if (m_shutdown) + return 0; + } + bool donotify = m_queue.size() >= size_t(m_max_queue_len); AudioBuffer* buf = m_queue.front(); @@ -408,6 +420,7 @@ namespace audiere { m_shutdown = true; m_cond.notify(); + m_buffer_cond.notify(); } ThreadedMixerDevice::ThreadedMixerDevice(int rate, int block_size, int queue_len) diff --git a/src/device_mixer.h b/src/device_mixer.h index 942bccc..43c5c4f 100644 --- a/src/device_mixer.h +++ b/src/device_mixer.h @@ -120,7 +120,7 @@ namespace audiere { void put_buffer(AudioBuffer* buffer); bool push(AudioBuffer* buffer); - AudioBuffer* pop(); + AudioBuffer* pop(bool wait = true); void shutdown(); |