mirror of
https://github.com/badaix/snapcast.git
synced 2025-06-13 00:01:52 +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
|
@ -72,6 +72,8 @@ void PipeStream::worker()
|
||||||
chronos::systemtimeofday(&tvChunk);
|
chronos::systemtimeofday(&tvChunk);
|
||||||
tvEncodedChunk_ = tvChunk;
|
tvEncodedChunk_ = tvChunk;
|
||||||
long nextTick = chronos::getTickCount();
|
long nextTick = chronos::getTickCount();
|
||||||
|
int idleFrames = 0;
|
||||||
|
int maxIdleFrames = sampleFormat_.rate*2;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (fd_ == -1)
|
if (fd_ == -1)
|
||||||
|
@ -86,6 +88,13 @@ void PipeStream::worker()
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
int count = read(fd_, chunk->payload + len, toRead - len);
|
int count = read(fd_, 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)
|
if (count < 0)
|
||||||
{
|
{
|
||||||
setState(kIdle);
|
setState(kIdle);
|
||||||
|
@ -94,8 +103,10 @@ void PipeStream::worker()
|
||||||
}
|
}
|
||||||
else if (count == 0)
|
else if (count == 0)
|
||||||
throw SnapException("end of file");
|
throw SnapException("end of file");
|
||||||
else
|
else {
|
||||||
len += count;
|
len += count;
|
||||||
|
idleFrames = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
while ((len < toRead) && active_);
|
while ((len < toRead) && active_);
|
||||||
|
|
||||||
|
|
|
@ -158,6 +158,8 @@ void ProcessStream::worker()
|
||||||
chronos::systemtimeofday(&tvChunk);
|
chronos::systemtimeofday(&tvChunk);
|
||||||
tvEncodedChunk_ = tvChunk;
|
tvEncodedChunk_ = tvChunk;
|
||||||
long nextTick = chronos::getTickCount();
|
long nextTick = chronos::getTickCount();
|
||||||
|
int idleFrames = 0;
|
||||||
|
int maxIdleFrames = sampleFormat_.rate*2;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
while (active_)
|
while (active_)
|
||||||
|
@ -169,6 +171,13 @@ void ProcessStream::worker()
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
int count = read(process_->getStdout(), chunk->payload + len, toRead - len);
|
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)
|
if (count < 0)
|
||||||
{
|
{
|
||||||
setState(kIdle);
|
setState(kIdle);
|
||||||
|
@ -177,8 +186,10 @@ void ProcessStream::worker()
|
||||||
}
|
}
|
||||||
else if (count == 0)
|
else if (count == 0)
|
||||||
throw SnapException("end of file");
|
throw SnapException("end of file");
|
||||||
else
|
else {
|
||||||
len += count;
|
len += count;
|
||||||
|
idleFrames = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
while ((len < toRead) && active_);
|
while ((len < toRead) && active_);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue