Play up to 2 seconds of silence before going idle. This helps keep clients in sync during short idle periods, e.g. song changes.

This commit is contained in:
Tommy Goode 2017-03-05 03:49:57 -06:00 committed by Johannes Pohl
parent 8c052e0946
commit f49a2f1bb0
2 changed files with 24 additions and 2 deletions

View file

@ -158,6 +158,8 @@ void ProcessStream::worker()
chronos::systemtimeofday(&tvChunk);
tvEncodedChunk_ = tvChunk;
long nextTick = chronos::getTickCount();
int idleFrames = 0;
int maxIdleFrames = sampleFormat_.rate*2;
try
{
while (active_)
@ -169,6 +171,13 @@ void ProcessStream::worker()
do
{
int count = read(process_->getStdout(), chunk->payload + len, toRead - len);
if (count < 0 && idleFrames < maxIdleFrames)
{
memset(chunk->payload + len, 0, toRead - len);
idleFrames += toRead - len;
len += toRead - len;
continue;
}
if (count < 0)
{
setState(kIdle);
@ -177,8 +186,10 @@ void ProcessStream::worker()
}
else if (count == 0)
throw SnapException("end of file");
else
else {
len += count;
idleFrames = 0;
}
}
while ((len < toRead) && active_);