diff options
author | jmarshallnz <jcmarsha@gmail.com> | 2014-03-10 15:08:57 +1300 |
---|---|---|
committer | jmarshallnz <jcmarsha@gmail.com> | 2014-03-10 15:08:57 +1300 |
commit | 5b7d56062a187bc4c3b8493597cc1fd8a6ed4a2f (patch) | |
tree | 78199cd460791f5c1eea95bb9dfc61af4ccf4a10 | |
parent | 6a35017aae3890b82a439467eb9c127402c4df1c (diff) | |
parent | a50426f1bb2266942622433e3a6b1ca2f50cda0d (diff) |
Merge pull request #4384 from Memphiz/osxbreakdrainbp
[osxsink] - fix deadloop in drain
-rw-r--r-- | xbmc/cores/AudioEngine/Sinks/AESinkDARWINIOS.cpp | 16 | ||||
-rw-r--r-- | xbmc/cores/AudioEngine/Sinks/AESinkDARWINOSX.cpp | 16 |
2 files changed, 26 insertions, 6 deletions
diff --git a/xbmc/cores/AudioEngine/Sinks/AESinkDARWINIOS.cpp b/xbmc/cores/AudioEngine/Sinks/AESinkDARWINIOS.cpp index 35747fdb87..130b8a9435 100644 --- a/xbmc/cores/AudioEngine/Sinks/AESinkDARWINIOS.cpp +++ b/xbmc/cores/AudioEngine/Sinks/AESinkDARWINIOS.cpp @@ -244,7 +244,7 @@ unsigned int CAAudioUnitSink::write(uint8_t *data, unsigned int frames) // we are using a timer here for beeing sure for timeouts // condvar can be woken spuriously as signaled XbmcThreads::EndTime timer(timeout); - condVar.wait(lock, timeout); + condVar.wait(mutex, timeout); if (!m_started && timer.IsTimePast()) return INT_MAX; } @@ -259,11 +259,21 @@ unsigned int CAAudioUnitSink::write(uint8_t *data, unsigned int frames) void CAAudioUnitSink::drain() { unsigned int bytes = m_buffer->GetReadSize(); - while (bytes) + unsigned int totalBytes = bytes; + int maxNumTimeouts = 3; + unsigned int timeout = 900 * bytes / (m_sampleRate * m_frameSize); + while (bytes && maxNumTimeouts > 0) { CSingleLock lock(mutex); - condVar.wait(mutex, 900 * bytes / (m_sampleRate * m_frameSize)); + XbmcThreads::EndTime timer(timeout); + condVar.wait(mutex, timeout); + bytes = m_buffer->GetReadSize(); + // if we timeout and don't + // consum bytes - decrease maxNumTimeouts + if (timer.IsTimePast() && bytes == totalBytes) + maxNumTimeouts--; + totalBytes = bytes; } } diff --git a/xbmc/cores/AudioEngine/Sinks/AESinkDARWINOSX.cpp b/xbmc/cores/AudioEngine/Sinks/AESinkDARWINOSX.cpp index e49551fa43..60eb532bf6 100644 --- a/xbmc/cores/AudioEngine/Sinks/AESinkDARWINOSX.cpp +++ b/xbmc/cores/AudioEngine/Sinks/AESinkDARWINOSX.cpp @@ -632,7 +632,7 @@ unsigned int CAESinkDARWINOSX::AddPackets(uint8_t *data, unsigned int frames, bo // we are using a timer here for beeing sure for timeouts // condvar can be woken spuriously as signaled XbmcThreads::EndTime timer(timeout); - condVar.wait(lock, timeout); + condVar.wait(mutex, timeout); if (!m_started && timer.IsTimePast()) return INT_MAX; } @@ -647,11 +647,21 @@ unsigned int CAESinkDARWINOSX::AddPackets(uint8_t *data, unsigned int frames, bo void CAESinkDARWINOSX::Drain() { int bytes = m_buffer->GetReadSize(); - while (bytes) + int totalBytes = bytes; + int maxNumTimeouts = 3; + unsigned int timeout = 900 * bytes / (m_format.m_sampleRate * m_format.m_frameSize); + while (bytes && maxNumTimeouts > 0) { CSingleLock lock(mutex); - condVar.wait(mutex, 900 * bytes / (m_format.m_sampleRate * m_format.m_frameSize)); + XbmcThreads::EndTime timer(timeout); + condVar.wait(mutex, timeout); + bytes = m_buffer->GetReadSize(); + // if we timeout and don't + // consum bytes - decrease maxNumTimeouts + if (timer.IsTimePast() && bytes == totalBytes) + maxNumTimeouts--; + totalBytes = bytes; } } |