Permalink
Browse files

[iossink/osxsink] - don't deadloop in drain when device is gone - but

handle timeout
  • Loading branch information...
1 parent e042b65 commit c7b5c584a55e93cc810cb90060e92affb512324f @Memphiz Memphiz committed Mar 7, 2014
Showing with 24 additions and 4 deletions.
  1. +12 −2 xbmc/cores/AudioEngine/Sinks/AESinkDARWINIOS.cpp
  2. +12 −2 xbmc/cores/AudioEngine/Sinks/AESinkDARWINOSX.cpp
@@ -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)
@FernetMenta
FernetMenta Mar 17, 2014 Member

@fritsch just noticed: you should reset the ringbuffer after the while loop. it may have timed out

{
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;
}
}
@@ -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 c7b5c58

Please sign in to comment.