mirror of
https://github.com/badaix/snapcast.git
synced 2025-04-29 18:27:12 +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
|
@ -16,7 +16,9 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif // NOMINMAX
|
||||
|
||||
#include "stream.hpp"
|
||||
#include "common/aixlog.hpp"
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -688,7 +688,7 @@ struct SinkNull : public Sink
|
|||
{
|
||||
}
|
||||
|
||||
void log(const Metadata& metadata, const std::string& message) override
|
||||
void log(const Metadata& /*metadata*/, const std::string& /*message*/) override
|
||||
{
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue