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
8e8fbe14
Commit
8e8fbe14
authored
Feb 22, 2021
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
output/snapcast: implement Drain()
parent
a8a39b6a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
1 deletion
+48
-1
Client.cxx
src/output/plugins/snapcast/Client.cxx
+4
-0
Client.hxx
src/output/plugins/snapcast/Client.hxx
+7
-0
Internal.hxx
src/output/plugins/snapcast/Internal.hxx
+14
-1
SnapcastOutputPlugin.cxx
src/output/plugins/snapcast/SnapcastOutputPlugin.cxx
+23
-0
No files found.
src/output/plugins/snapcast/Client.cxx
View file @
8e8fbe14
...
...
@@ -76,6 +76,10 @@ SnapcastClient::LockPopQueue() noexcept
auto
chunk
=
std
::
move
(
chunks
.
front
());
chunks
.
pop
();
if
(
chunks
.
empty
())
output
.
drain_cond
.
notify_one
();
return
chunk
;
}
...
...
src/output/plugins/snapcast/Client.hxx
View file @
8e8fbe14
...
...
@@ -68,6 +68,13 @@ public:
/**
* Caller must lock the mutex.
*/
bool
IsDrained
()
const
noexcept
{
return
chunks
.
empty
();
}
/**
* Caller must lock the mutex.
*/
void
Cancel
()
noexcept
{
ClearQueue
(
chunks
);
}
...
...
src/output/plugins/snapcast/Internal.hxx
View file @
8e8fbe14
...
...
@@ -24,6 +24,7 @@
#include "output/Interface.hxx"
#include "output/Timer.hxx"
#include "thread/Mutex.hxx"
#include "thread/Cond.hxx"
#include "event/ServerSocket.hxx"
#include "event/InjectEvent.hxx"
#include "util/AllocatedArray.hxx"
...
...
@@ -82,6 +83,12 @@ public:
*/
mutable
Mutex
mutex
;
/**
* This cond is signalled when a #SnapcastClient has an empty
* queue.
*/
Cond
drain_cond
;
SnapcastOutput
(
EventLoop
&
_loop
,
const
ConfigBlock
&
block
);
~
SnapcastOutput
()
noexcept
override
;
...
...
@@ -162,13 +169,19 @@ public:
size_t
Play
(
const
void
*
chunk
,
size_t
size
)
override
;
// TODO:
void Drain() override;
void
Drain
()
override
;
void
Cancel
()
noexcept
override
;
bool
Pause
()
override
;
private
:
void
OnInject
()
noexcept
;
/**
* Caller must lock the mutex.
*/
[[
gnu
::
pure
]]
bool
IsDrained
()
const
noexcept
;
/* virtual methods from class ServerSocket */
void
OnAccept
(
UniqueSocketDescriptor
fd
,
SocketAddress
address
,
int
uid
)
noexcept
override
;
...
...
src/output/plugins/snapcast/SnapcastOutputPlugin.cxx
View file @
8e8fbe14
...
...
@@ -181,6 +181,9 @@ SnapcastOutput::RemoveClient(SnapcastClient &client) noexcept
client
.
unlink
();
delete
&
client
;
if
(
clients
.
empty
())
drain_cond
.
notify_one
();
}
std
::
chrono
::
steady_clock
::
duration
...
...
@@ -261,6 +264,26 @@ SnapcastOutput::Pause()
return
true
;
}
inline
bool
SnapcastOutput
::
IsDrained
()
const
noexcept
{
if
(
!
chunks
.
empty
())
return
false
;
for
(
const
auto
&
client
:
clients
)
if
(
!
client
.
IsDrained
())
return
false
;
return
true
;
}
void
SnapcastOutput
::
Drain
()
{
std
::
unique_lock
<
Mutex
>
protect
(
mutex
);
drain_cond
.
wait
(
protect
,
[
this
]{
return
IsDrained
();
});
}
void
SnapcastOutput
::
Cancel
()
noexcept
{
...
...
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