Permalink
Browse files

Merge pull request #4383 from Memphiz/osxbreakdrain

[osxsink] - fix deadloop in drain
  • Loading branch information...
2 parents e042b65 + dc701c0 commit 59e9f7f11fb0fc3fccebf7ed19dddb17c6d7f342 @jmarshallnz jmarshallnz committed Mar 10, 2014
Showing with 26 additions and 6 deletions.
  1. +13 −3 xbmc/cores/AudioEngine/Sinks/AESinkDARWINIOS.cpp
  2. +13 −3 xbmc/cores/AudioEngine/Sinks/AESinkDARWINOSX.cpp
View
16 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;
}
}
View
16 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;
}
}

0 comments on commit 59e9f7f

Please sign in to comment.