summaryrefslogtreecommitdiff
path: root/Servers
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-11-23 17:21:12 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-11-23 17:21:12 +0100
commit84cb91de3874505bf55d9089aa31efab615875c8 (patch)
tree2d4a557c570df0d6fd4df9ddb6de7fe68ad81f79 /Servers
parent00ab9488ad7b3814c9561d4d964242b64f96fae3 (diff)
downloadserenity-84cb91de3874505bf55d9089aa31efab615875c8.zip
AudioServer: Broadcast muted state changes to all clients
Diffstat (limited to 'Servers')
-rw-r--r--Servers/AudioServer/ASClientConnection.cpp14
-rw-r--r--Servers/AudioServer/ASClientConnection.h4
-rw-r--r--Servers/AudioServer/ASMixer.cpp5
-rw-r--r--Servers/AudioServer/AudioClient.ipc1
4 files changed, 24 insertions, 0 deletions
diff --git a/Servers/AudioServer/ASClientConnection.cpp b/Servers/AudioServer/ASClientConnection.cpp
index e6704db19c..b328b228de 100644
--- a/Servers/AudioServer/ASClientConnection.cpp
+++ b/Servers/AudioServer/ASClientConnection.cpp
@@ -13,6 +13,15 @@
static HashMap<int, RefPtr<ASClientConnection>> s_connections;
+void ASClientConnection::for_each(Function<void(ASClientConnection&)> callback)
+{
+ NonnullRefPtrVector<ASClientConnection> connections;
+ for (auto& it : s_connections)
+ connections.append(*it.value);
+ for (auto& connection : connections)
+ callback(connection);
+}
+
ASClientConnection::ASClientConnection(CLocalSocket& client_socket, int client_id, ASMixer& mixer)
: ConnectionNG(*this, client_socket, client_id)
, m_mixer(mixer)
@@ -34,6 +43,11 @@ void ASClientConnection::did_finish_playing_buffer(Badge<ASBufferQueue>, int buf
post_message(AudioClient::FinishedPlayingBuffer(buffer_id));
}
+void ASClientConnection::did_change_muted_state(Badge<ASMixer>, bool muted)
+{
+ post_message(AudioClient::MutedStateChanged(muted));
+}
+
OwnPtr<AudioServer::GreetResponse> ASClientConnection::handle(const AudioServer::Greet& message)
{
set_client_pid(message.client_pid());
diff --git a/Servers/AudioServer/ASClientConnection.h b/Servers/AudioServer/ASClientConnection.h
index 4147a231d0..aa67ebc08f 100644
--- a/Servers/AudioServer/ASClientConnection.h
+++ b/Servers/AudioServer/ASClientConnection.h
@@ -13,10 +13,14 @@ class ASClientConnection final : public IPC::Server::ConnectionNG<AudioServerEnd
public:
explicit ASClientConnection(CLocalSocket&, int client_id, ASMixer& mixer);
~ASClientConnection() override;
+
void did_finish_playing_buffer(Badge<ASBufferQueue>, int buffer_id);
+ void did_change_muted_state(Badge<ASMixer>, bool muted);
virtual void die() override;
+ static void for_each(Function<void(ASClientConnection&)>);
+
private:
virtual OwnPtr<AudioServer::GreetResponse> handle(const AudioServer::Greet&) override;
virtual OwnPtr<AudioServer::GetMainMixVolumeResponse> handle(const AudioServer::GetMainMixVolume&) override;
diff --git a/Servers/AudioServer/ASMixer.cpp b/Servers/AudioServer/ASMixer.cpp
index 2cd71e8bec..138fb603a7 100644
--- a/Servers/AudioServer/ASMixer.cpp
+++ b/Servers/AudioServer/ASMixer.cpp
@@ -101,7 +101,12 @@ void ASMixer::mix()
void ASMixer::set_muted(bool muted)
{
+ if (m_muted == muted)
+ return;
m_muted = muted;
+ ASClientConnection::for_each([muted](ASClientConnection& client) {
+ client.did_change_muted_state({}, muted);
+ });
}
ASBufferQueue::ASBufferQueue(ASClientConnection& client)
diff --git a/Servers/AudioServer/AudioClient.ipc b/Servers/AudioServer/AudioClient.ipc
index ed9ba77b3a..12aa2d0b92 100644
--- a/Servers/AudioServer/AudioClient.ipc
+++ b/Servers/AudioServer/AudioClient.ipc
@@ -1,4 +1,5 @@
endpoint AudioClient = 82
{
FinishedPlayingBuffer(i32 buffer_id) =|
+ MutedStateChanged(bool muted) =|
}