mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:17:45 +00:00
AudioServer: Broadcast muted state changes to all clients
This commit is contained in:
parent
00ab9488ad
commit
84cb91de38
6 changed files with 37 additions and 1 deletions
|
@ -77,6 +77,14 @@ int AClientConnection::get_playing_buffer()
|
||||||
return send_sync<AudioServer::GetPlayingBuffer>()->buffer_id();
|
return send_sync<AudioServer::GetPlayingBuffer>()->buffer_id();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AClientConnection::handle(const AudioClient::FinishedPlayingBuffer&)
|
void AClientConnection::handle(const AudioClient::FinishedPlayingBuffer& message)
|
||||||
{
|
{
|
||||||
|
if (on_finish_playing_buffer)
|
||||||
|
on_finish_playing_buffer(message.buffer_id());
|
||||||
|
}
|
||||||
|
|
||||||
|
void AClientConnection::handle(const AudioClient::MutedStateChanged& message)
|
||||||
|
{
|
||||||
|
if (on_muted_state_change)
|
||||||
|
on_muted_state_change(message.muted());
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,10 @@ public:
|
||||||
void set_paused(bool paused);
|
void set_paused(bool paused);
|
||||||
void clear_buffer(bool paused = false);
|
void clear_buffer(bool paused = false);
|
||||||
|
|
||||||
|
Function<void(i32 buffer_id)> on_finish_playing_buffer;
|
||||||
|
Function<void(bool muted)> on_muted_state_change;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void handle(const AudioClient::FinishedPlayingBuffer&) override;
|
virtual void handle(const AudioClient::FinishedPlayingBuffer&) override;
|
||||||
|
virtual void handle(const AudioClient::MutedStateChanged&) override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -13,6 +13,15 @@
|
||||||
|
|
||||||
static HashMap<int, RefPtr<ASClientConnection>> s_connections;
|
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)
|
ASClientConnection::ASClientConnection(CLocalSocket& client_socket, int client_id, ASMixer& mixer)
|
||||||
: ConnectionNG(*this, client_socket, client_id)
|
: ConnectionNG(*this, client_socket, client_id)
|
||||||
, m_mixer(mixer)
|
, m_mixer(mixer)
|
||||||
|
@ -34,6 +43,11 @@ void ASClientConnection::did_finish_playing_buffer(Badge<ASBufferQueue>, int buf
|
||||||
post_message(AudioClient::FinishedPlayingBuffer(buffer_id));
|
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)
|
OwnPtr<AudioServer::GreetResponse> ASClientConnection::handle(const AudioServer::Greet& message)
|
||||||
{
|
{
|
||||||
set_client_pid(message.client_pid());
|
set_client_pid(message.client_pid());
|
||||||
|
|
|
@ -13,10 +13,14 @@ class ASClientConnection final : public IPC::Server::ConnectionNG<AudioServerEnd
|
||||||
public:
|
public:
|
||||||
explicit ASClientConnection(CLocalSocket&, int client_id, ASMixer& mixer);
|
explicit ASClientConnection(CLocalSocket&, int client_id, ASMixer& mixer);
|
||||||
~ASClientConnection() override;
|
~ASClientConnection() override;
|
||||||
|
|
||||||
void did_finish_playing_buffer(Badge<ASBufferQueue>, int buffer_id);
|
void did_finish_playing_buffer(Badge<ASBufferQueue>, int buffer_id);
|
||||||
|
void did_change_muted_state(Badge<ASMixer>, bool muted);
|
||||||
|
|
||||||
virtual void die() override;
|
virtual void die() override;
|
||||||
|
|
||||||
|
static void for_each(Function<void(ASClientConnection&)>);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual OwnPtr<AudioServer::GreetResponse> handle(const AudioServer::Greet&) override;
|
virtual OwnPtr<AudioServer::GreetResponse> handle(const AudioServer::Greet&) override;
|
||||||
virtual OwnPtr<AudioServer::GetMainMixVolumeResponse> handle(const AudioServer::GetMainMixVolume&) override;
|
virtual OwnPtr<AudioServer::GetMainMixVolumeResponse> handle(const AudioServer::GetMainMixVolume&) override;
|
||||||
|
|
|
@ -101,7 +101,12 @@ void ASMixer::mix()
|
||||||
|
|
||||||
void ASMixer::set_muted(bool muted)
|
void ASMixer::set_muted(bool muted)
|
||||||
{
|
{
|
||||||
|
if (m_muted == muted)
|
||||||
|
return;
|
||||||
m_muted = muted;
|
m_muted = muted;
|
||||||
|
ASClientConnection::for_each([muted](ASClientConnection& client) {
|
||||||
|
client.did_change_muted_state({}, muted);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ASBufferQueue::ASBufferQueue(ASClientConnection& client)
|
ASBufferQueue::ASBufferQueue(ASClientConnection& client)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
endpoint AudioClient = 82
|
endpoint AudioClient = 82
|
||||||
{
|
{
|
||||||
FinishedPlayingBuffer(i32 buffer_id) =|
|
FinishedPlayingBuffer(i32 buffer_id) =|
|
||||||
|
MutedStateChanged(bool muted) =|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue