diff options
author | Luo Jinghua <sunmoon1997@gmail.com> | 2012-05-16 18:10:03 +0800 |
---|---|---|
committer | Luo Jinghua <sunmoon1997@gmail.com> | 2012-05-16 18:10:03 +0800 |
commit | 8c52ea68921f8c9047e1bb693cc43542069cce85 (patch) | |
tree | c3aaeb4530ccf05d386ac86edd46d3ec6850f422 /src | |
parent | ff11c2a40f26327e9a6a8c415736607bdd9cccf5 (diff) |
Wait for the available event only if the more space is needed
Diffstat (limited to 'src')
-rw-r--r-- | src/device_nexus.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/device_nexus.cpp b/src/device_nexus.cpp index 9d9e203..b8c3762 100644 --- a/src/device_nexus.cpp +++ b/src/device_nexus.cpp @@ -83,7 +83,7 @@ namespace audiere { int rate, int buffer_size) : MixerDevice(rate), m_platform(platform), m_playback_id(playback_id), - m_playback(playback), m_mixer(mixer), m_rate(rate), m_paused(false) + m_playback(playback), m_mixer(mixer), m_paused(false), m_rate(rate) { m_display = platform->getDisplay(); m_buffer_size = buffer_size; @@ -164,14 +164,21 @@ namespace audiere { sample_len = m_buffer_size / 4; sample_left = read(sample_len, sample_buf); + NEXUS_AudioPlaybackStatus status; while (sample_left > 0) { void *buffer = 0; size_t buffersize = 0; BERR_Code err; - err = BKNI_WaitForEvent(m_event, 1000); - if (err) - break; + NEXUS_AudioPlayback_GetStatus(m_playback, &status); + if (!status.started && !m_paused) + break; + + if (status.fifoSize - status.queuedBytes < sample_left * 4) { + err = BKNI_WaitForEvent(m_event, 500); + if (err) + continue; + } ScopedLock lock(m_mutex); @@ -183,7 +190,7 @@ namespace audiere { if (err) break; - if (buffersize && buffer) { + if (buffersize >= sample_left * 4 && buffer) { /* Copy samples into buffer */ size_t samples = buffersize / 4; if (samples > sample_left) |