mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-31 09:56:16 +02:00
Fix "last seen" timestamp
This commit is contained in:
parent
4587637487
commit
90785a87da
4 changed files with 32 additions and 12 deletions
|
@ -59,8 +59,26 @@ public:
|
||||||
bool waitForChunk(const std::chrono::milliseconds& timeout) const;
|
bool waitForChunk(const std::chrono::milliseconds& timeout) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/// Request an audio chunk from the front of the stream.
|
||||||
|
/// @param outputBuffer will be filled with the chunk
|
||||||
|
/// @param frames the number of requested frames
|
||||||
|
/// @return the timepoint when this chunk should be audible
|
||||||
chronos::time_point_clk getNextPlayerChunk(void* outputBuffer, uint32_t frames);
|
chronos::time_point_clk getNextPlayerChunk(void* outputBuffer, uint32_t frames);
|
||||||
|
|
||||||
|
/// Request an audio chunk from the front of the stream with a tempo adaption
|
||||||
|
/// @param outputBuffer will be filled with the chunk
|
||||||
|
/// @param frames the number of requested frames
|
||||||
|
/// @param framesCorrection number of frames that should be added or removed.
|
||||||
|
/// The function will allways return "frames" frames, but will fit "frames + framesCorrection" frames into "frames"
|
||||||
|
/// so if frames is 100 and framesCorrection is 2, 102 frames will be read from the stream and 2 frames will be removed.
|
||||||
|
/// This makes us "fast-forward" by 2 frames, or if framesCorrection is -3, 97 frames will be read from the stream and
|
||||||
|
/// filled with 3 frames (simply by dublication), this makes us effectively slower
|
||||||
|
/// @return the timepoint when this chunk should be audible
|
||||||
chronos::time_point_clk getNextPlayerChunk(void* outputBuffer, uint32_t frames, int32_t framesCorrection);
|
chronos::time_point_clk getNextPlayerChunk(void* outputBuffer, uint32_t frames, int32_t framesCorrection);
|
||||||
|
|
||||||
|
/// Request a silent audio chunk
|
||||||
|
/// @param outputBuffer will be filled with the chunk
|
||||||
|
/// @param frames the number of requested frames
|
||||||
void getSilentPlayerChunk(void* outputBuffer, uint32_t frames) const;
|
void getSilentPlayerChunk(void* outputBuffer, uint32_t frames) const;
|
||||||
|
|
||||||
void updateBuffers(int age);
|
void updateBuffers(int age);
|
||||||
|
|
|
@ -39,7 +39,7 @@ void TimeProvider::setDiffToServer(double ms)
|
||||||
{
|
{
|
||||||
static int32_t lastTimeSync = 0;
|
static int32_t lastTimeSync = 0;
|
||||||
timeval now;
|
timeval now;
|
||||||
chronos::systemtimeofday(&now);
|
chronos::steadytimeofday(&now);
|
||||||
|
|
||||||
/// clear diffBuffer if last update is older than a minute
|
/// clear diffBuffer if last update is older than a minute
|
||||||
if (!diffBuffer_.empty() && (std::abs(now.tv_sec - lastTimeSync) > 60))
|
if (!diffBuffer_.empty() && (std::abs(now.tv_sec - lastTimeSync) > 60))
|
||||||
|
|
|
@ -64,13 +64,12 @@ enum message_type
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct tv
|
struct tv
|
||||||
{
|
{
|
||||||
tv()
|
tv()
|
||||||
{
|
{
|
||||||
timeval t;
|
timeval t;
|
||||||
chronos::systemtimeofday(&t);
|
chronos::steadytimeofday(&t);
|
||||||
sec = t.tv_sec;
|
sec = t.tv_sec;
|
||||||
usec = t.tv_usec;
|
usec = t.tv_usec;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,13 +29,12 @@
|
||||||
|
|
||||||
namespace chronos
|
namespace chronos
|
||||||
{
|
{
|
||||||
typedef std::chrono::steady_clock clk;
|
using clk = std::chrono::steady_clock;
|
||||||
// typedef std::chrono::system_clock clk;
|
using time_point_clk = std::chrono::time_point<clk>;
|
||||||
typedef std::chrono::time_point<clk> time_point_clk;
|
using sec = std::chrono::seconds;
|
||||||
typedef std::chrono::seconds sec;
|
using msec = std::chrono::milliseconds;
|
||||||
typedef std::chrono::milliseconds msec;
|
using usec = std::chrono::microseconds;
|
||||||
typedef std::chrono::microseconds usec;
|
using nsec = std::chrono::nanoseconds;
|
||||||
typedef std::chrono::nanoseconds nsec;
|
|
||||||
|
|
||||||
template <class Clock>
|
template <class Clock>
|
||||||
inline static void timeofday(struct timeval* tv)
|
inline static void timeofday(struct timeval* tv)
|
||||||
|
@ -46,10 +45,14 @@ inline static void timeofday(struct timeval* tv)
|
||||||
tv->tv_usec = microsecs.count() % 1000000;
|
tv->tv_usec = microsecs.count() % 1000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline static void steadytimeofday(struct timeval* tv)
|
||||||
|
{
|
||||||
|
timeofday<clk>(tv);
|
||||||
|
}
|
||||||
|
|
||||||
inline static void systemtimeofday(struct timeval* tv)
|
inline static void systemtimeofday(struct timeval* tv)
|
||||||
{
|
{
|
||||||
// gettimeofday(tv, nullptr);
|
timeofday<std::chrono::system_clock>(tv);
|
||||||
timeofday<clk>(tv);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ToDuration>
|
template <class ToDuration>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue