output/snapcast: calculate the latency for TIME responses
This commit is contained in:
parent
e875da5d38
commit
dfc67c45c7
@ -22,6 +22,7 @@
|
|||||||
#include "Timestamp.hxx"
|
#include "Timestamp.hxx"
|
||||||
#include "Internal.hxx"
|
#include "Internal.hxx"
|
||||||
#include "tag/RiffFormat.hxx"
|
#include "tag/RiffFormat.hxx"
|
||||||
|
#include "event/Loop.hxx"
|
||||||
#include "net/SocketError.hxx"
|
#include "net/SocketError.hxx"
|
||||||
#include "net/UniqueSocketDescriptor.hxx"
|
#include "net/UniqueSocketDescriptor.hxx"
|
||||||
#include "util/StringView.hxx"
|
#include "util/StringView.hxx"
|
||||||
@ -146,7 +147,8 @@ SendTime(SocketDescriptor s, const PackedBE16 id,
|
|||||||
const SnapcastBase &request_header,
|
const SnapcastBase &request_header,
|
||||||
const SnapcastTime &request_payload) noexcept
|
const SnapcastTime &request_payload) noexcept
|
||||||
{
|
{
|
||||||
SnapcastTime payload = request_payload; // TODO
|
SnapcastTime payload = request_payload;
|
||||||
|
payload.latency = request_header.received - request_header.sent;
|
||||||
|
|
||||||
SnapcastBase base{};
|
SnapcastBase base{};
|
||||||
base.type = uint16_t(SnapcastMessageType::TIME);
|
base.type = uint16_t(SnapcastMessageType::TIME);
|
||||||
@ -196,12 +198,14 @@ SnapcastClient::SendWireChunk(ConstBuffer<void> payload,
|
|||||||
BufferedSocket::InputResult
|
BufferedSocket::InputResult
|
||||||
SnapcastClient::OnSocketInput(void *data, size_t length) noexcept
|
SnapcastClient::OnSocketInput(void *data, size_t length) noexcept
|
||||||
{
|
{
|
||||||
const auto &base = *(const SnapcastBase *)data;
|
auto &base = *(SnapcastBase *)data;
|
||||||
|
|
||||||
if (length < sizeof(base) ||
|
if (length < sizeof(base) ||
|
||||||
length < sizeof(base) + base.size)
|
length < sizeof(base) + base.size)
|
||||||
return InputResult::MORE;
|
return InputResult::MORE;
|
||||||
|
|
||||||
|
base.received = ToSnapcastTimestamp(GetEventLoop().SteadyNow());
|
||||||
|
|
||||||
ConsumeInput(sizeof(base) + base.size);
|
ConsumeInput(sizeof(base) + base.size);
|
||||||
|
|
||||||
const ConstBuffer<void> payload{&base + 1, base.size};
|
const ConstBuffer<void> payload{&base + 1, base.size};
|
||||||
|
@ -35,6 +35,21 @@ enum class SnapcastMessageType : uint16_t {
|
|||||||
|
|
||||||
struct SnapcastTimestamp {
|
struct SnapcastTimestamp {
|
||||||
PackedLE32 sec, usec;
|
PackedLE32 sec, usec;
|
||||||
|
|
||||||
|
constexpr SnapcastTimestamp operator-(SnapcastTimestamp other) const noexcept {
|
||||||
|
const uint32_t a_sec = sec, a_usec = usec;
|
||||||
|
const uint32_t b_sec = other.sec, b_usec = other.usec;
|
||||||
|
|
||||||
|
uint32_t result_sec = a_sec - b_sec;
|
||||||
|
uint32_t result_usec = a_usec - b_usec;
|
||||||
|
|
||||||
|
if (a_usec < b_usec) {
|
||||||
|
--result_sec;
|
||||||
|
result_usec += 1'000'0000;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {result_sec, result_usec};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SnapcastBase {
|
struct SnapcastBase {
|
||||||
|
Loading…
Reference in New Issue
Block a user