mirror of
https://github.com/badaix/snapcast.git
synced 2025-07-07 19:57:43 +02:00
Change stream reader to use actual chunk duration
e.g. a configured chunk_ms of 11 will read a 44.1kHz stream in chunks of 485 frames (=10.9977ms)
This commit is contained in:
parent
12f828ed43
commit
a8998997e9
8 changed files with 45 additions and 33 deletions
|
@ -119,23 +119,23 @@ void PosixStream::do_read()
|
|||
{
|
||||
first_ = false;
|
||||
chronos::systemtimeofday(&tvEncodedChunk_);
|
||||
nextTick_ = chronos::getTickCount() + buffer_ms_;
|
||||
nextTick_ = std::chrono::steady_clock::now() + std::chrono::milliseconds(buffer_ms_);
|
||||
}
|
||||
encoder_->encode(chunk_.get());
|
||||
nextTick_ += chunk_ms_;
|
||||
long currentTick = chronos::getTickCount();
|
||||
nextTick_ += chunk_->duration<std::chrono::nanoseconds>();
|
||||
auto currentTick = std::chrono::steady_clock::now();
|
||||
|
||||
if (nextTick_ >= currentTick)
|
||||
{
|
||||
// synchronize reads to an interval of chunk_ms_
|
||||
wait(read_timer_, std::chrono::milliseconds(nextTick_ - currentTick), [this] { do_read(); });
|
||||
wait(read_timer_, nextTick_ - currentTick, [this] { do_read(); });
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// reading chunk_ms_ took longer than chunk_ms_
|
||||
pcmListener_->onResync(this, currentTick - nextTick_);
|
||||
nextTick_ = currentTick + buffer_ms_;
|
||||
pcmListener_->onResync(this, std::chrono::duration_cast<std::chrono::milliseconds>(currentTick - nextTick_).count());
|
||||
nextTick_ = currentTick + std::chrono::milliseconds(buffer_ms_);
|
||||
first_ = true;
|
||||
do_read();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue