mirror of
https://github.com/badaix/snapcast.git
synced 2025-06-08 13:51:43 +02:00
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:
parent
8c052e0946
commit
f49a2f1bb0
2 changed files with 24 additions and 2 deletions
|
@ -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_);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue