mirror of
https://github.com/badaix/snapcast.git
synced 2025-06-01 02:11:47 +02:00
Speed up time sync after standby
This commit is contained in:
parent
c85b16454c
commit
bfbd9e05a7
3 changed files with 11 additions and 6 deletions
|
@ -19,6 +19,8 @@
|
|||
#include "time_provider.hpp"
|
||||
#include "common/aixlog.hpp"
|
||||
|
||||
#include <chrono>
|
||||
|
||||
|
||||
TimeProvider::TimeProvider() : diffToServer_(0)
|
||||
{
|
||||
|
@ -37,18 +39,19 @@ void TimeProvider::setDiff(const tv& c2s, const tv& s2c)
|
|||
|
||||
void TimeProvider::setDiffToServer(double ms)
|
||||
{
|
||||
static int32_t lastTimeSync = 0;
|
||||
timeval now;
|
||||
chronos::steadytimeofday(&now);
|
||||
using namespace std::chrono_literals;
|
||||
auto now = std::chrono::system_clock::now();
|
||||
static auto lastTimeSync = now;
|
||||
auto diff = chronos::abs(now - lastTimeSync);
|
||||
|
||||
/// clear diffBuffer if last update is older than a minute
|
||||
if (!diffBuffer_.empty() && (std::abs(now.tv_sec - lastTimeSync) > 60))
|
||||
if (!diffBuffer_.empty() && (diff > 60s))
|
||||
{
|
||||
LOG(INFO) << "Last time sync older than a minute. Clearing time buffer\n";
|
||||
diffToServer_ = static_cast<chronos::usec::rep>(ms * 1000);
|
||||
diffBuffer_.clear();
|
||||
}
|
||||
lastTimeSync = now.tv_sec;
|
||||
lastTimeSync = now;
|
||||
|
||||
diffBuffer_.add(static_cast<chronos::usec::rep>(ms * 1000));
|
||||
diffToServer_ = diffBuffer_.median();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue