Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
dfc67c45
Commit
dfc67c45
authored
Feb 22, 2021
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
output/snapcast: calculate the latency for TIME responses
parent
e875da5d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
2 deletions
+21
-2
Client.cxx
src/output/plugins/snapcast/Client.cxx
+6
-2
Protocol.hxx
src/output/plugins/snapcast/Protocol.hxx
+15
-0
No files found.
src/output/plugins/snapcast/Client.cxx
View file @
dfc67c45
...
@@ -22,6 +22,7 @@
...
@@ -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,
...
@@ -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,
...
@@ -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
};
...
...
src/output/plugins/snapcast/Protocol.hxx
View file @
dfc67c45
...
@@ -35,6 +35,21 @@ enum class SnapcastMessageType : uint16_t {
...
@@ -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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment