mirror of
https://github.com/badaix/snapcast.git
synced 2025-07-17 08:27:42 +02:00
Reset chunk if there are no new ones to avoid loop
This commit is contained in:
parent
f8fac84b09
commit
5928d0e77b
1 changed files with 11 additions and 4 deletions
|
@ -328,9 +328,14 @@ bool Stream::getPlayerChunk(void* outputBuffer, const cs::usec& outputBufferDacT
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
time_t now = time(nullptr);
|
||||||
if (!chunk_ && !chunks_.try_pop(chunk_))
|
if (!chunk_ && !chunks_.try_pop(chunk_))
|
||||||
{
|
{
|
||||||
LOG(INFO, LOG_TAG) << "no chunks available\n";
|
if (now != lastUpdate_)
|
||||||
|
{
|
||||||
|
lastUpdate_ = now;
|
||||||
|
LOG(INFO, LOG_TAG) << "no chunks available\n";
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,8 +351,8 @@ bool Stream::getPlayerChunk(void* outputBuffer, const cs::usec& outputBufferDacT
|
||||||
{
|
{
|
||||||
cs::nsec req_chunk_duration = cs::nsec(static_cast<cs::nsec::rep>(frames / format_.nsRate()));
|
cs::nsec req_chunk_duration = cs::nsec(static_cast<cs::nsec::rep>(frames / format_.nsRate()));
|
||||||
cs::usec age = std::chrono::duration_cast<cs::usec>(TimeProvider::serverNow() - chunk_->start()) - bufferMs_ + outputBufferDacTime;
|
cs::usec age = std::chrono::duration_cast<cs::usec>(TimeProvider::serverNow() - chunk_->start()) - bufferMs_ + outputBufferDacTime;
|
||||||
// LOG(INFO, LOG_TAG) << "age: " << age.count() / 1000 << ", buffer: " << std::chrono::duration_cast<chrono::milliseconds>(chunk_duration).count()
|
// LOG(INFO, LOG_TAG) << "age: " << age.count() / 1000 << ", buffer: " <<
|
||||||
// << "\n";
|
// std::chrono::duration_cast<chrono::milliseconds>(req_chunk_duration).count() << "\n";
|
||||||
if (age < -req_chunk_duration)
|
if (age < -req_chunk_duration)
|
||||||
{
|
{
|
||||||
// the oldest chunk (top of the stream) is too young for the buffer
|
// the oldest chunk (top of the stream) is too young for the buffer
|
||||||
|
@ -360,7 +365,10 @@ bool Stream::getPlayerChunk(void* outputBuffer, const cs::usec& outputBufferDacT
|
||||||
{
|
{
|
||||||
if (age.count() > 0)
|
if (age.count() > 0)
|
||||||
{
|
{
|
||||||
|
LOG(DEBUG, LOG_TAG) << "age > 0: " << age.count() / 1000 << "ms\n";
|
||||||
// age > 0: the top of the stream is too old. We must fast foward.
|
// age > 0: the top of the stream is too old. We must fast foward.
|
||||||
|
// delete the current chunk, it's too old. This will avoid an endless loop if there is no chunk in the queue.
|
||||||
|
chunk_ = nullptr;
|
||||||
while (chunks_.try_pop(chunk_))
|
while (chunks_.try_pop(chunk_))
|
||||||
{
|
{
|
||||||
age = std::chrono::duration_cast<cs::usec>(TimeProvider::serverNow() - chunk_->start()) - bufferMs_ + outputBufferDacTime;
|
age = std::chrono::duration_cast<cs::usec>(TimeProvider::serverNow() - chunk_->start()) - bufferMs_ + outputBufferDacTime;
|
||||||
|
@ -463,7 +471,6 @@ bool Stream::getPlayerChunk(void* outputBuffer, const cs::usec& outputBufferDacT
|
||||||
updateBuffers(age.count());
|
updateBuffers(age.count());
|
||||||
|
|
||||||
// print sync stats
|
// print sync stats
|
||||||
time_t now = time(nullptr);
|
|
||||||
if (now != lastUpdate_)
|
if (now != lastUpdate_)
|
||||||
{
|
{
|
||||||
lastUpdate_ = now;
|
lastUpdate_ = now;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue