ladybird/Userland/Services/AudioServer/ConnectionFromManagerClient.cpp
kleines Filmröllchen 03fac609ee AudioServer+Userland: Separate audio IPC into normal client and manager
This is a sensible separation of concerns that mirrors the WindowServer
IPC split. On the one hand, there is the "normal" audio interface, used
for clients that play audio, which is the primary service of
AudioServer. On the other hand, there is the management interface,
which, like the WindowManager endpoint, provides higher-level control
over clients and the server itself.

The reasoning for this split are manifold, as mentioned we are mirroring
the WindowServer split. Another indication to the sensibility of the
split is that no single audio client used the APIs of both interfaces.
Also, useless audio queues are no longer created for managing clients
(since those don't even exist, just like there's no window backing
bitmap for window managing clients), eliminating any bugs that may occur
there as they have in the past.

Implementation-wise, we just move all the APIs and implementations from
the old AudioServer into the AudioManagerServer (and respective clients,
of course). There is one point of duplication, namely the hardware
sample rate. This will be fixed in combination with per-client sample
rate, eliminating client-side resampling and the related update bugs.
For now, we keep one legacy API to simplify the transition.

The new AudioManagerServer also gains a hardware sample rate change
callback to have exact symmetry on the main server parameters (getter,
setter, and callback).
2023-06-25 00:16:44 +02:00

75 lines
2.0 KiB
C++

/*
* Copyright (c) 2023, kleines Filmröllchen <filmroellchen@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "ConnectionFromManagerClient.h"
namespace AudioServer {
static HashMap<int, RefPtr<ConnectionFromManagerClient>> s_connections;
ConnectionFromManagerClient::ConnectionFromManagerClient(NonnullOwnPtr<Core::LocalSocket> client_socket, int client_id, Mixer& mixer)
: IPC::ConnectionFromClient<AudioManagerClientEndpoint, AudioManagerServerEndpoint>(*this, move(client_socket), client_id)
, m_mixer(mixer)
{
s_connections.set(client_id, *this);
}
void ConnectionFromManagerClient::die()
{
s_connections.remove(client_id());
}
void ConnectionFromManagerClient::for_each(Function<void(ConnectionFromManagerClient&)> callback)
{
Vector<NonnullRefPtr<ConnectionFromManagerClient>> connections;
for (auto& it : s_connections)
connections.append(*it.value);
for (auto& connection : connections)
callback(connection);
}
void ConnectionFromManagerClient::did_change_main_mix_muted_state(Badge<Mixer>, bool muted)
{
async_main_mix_muted_state_changed(muted);
}
void ConnectionFromManagerClient::did_change_main_mix_volume(Badge<Mixer>, double volume)
{
async_main_mix_volume_changed(volume);
}
Messages::AudioManagerServer::GetMainMixVolumeResponse ConnectionFromManagerClient::get_main_mix_volume()
{
return m_mixer.main_volume();
}
void ConnectionFromManagerClient::set_main_mix_volume(double volume)
{
m_mixer.set_main_volume(volume);
}
Messages::AudioManagerServer::GetDeviceSampleRateResponse ConnectionFromManagerClient::get_device_sample_rate()
{
return { m_mixer.audiodevice_get_sample_rate() };
}
void ConnectionFromManagerClient::set_device_sample_rate(u32 sample_rate)
{
m_mixer.audiodevice_set_sample_rate(sample_rate);
}
Messages::AudioManagerServer::IsMainMixMutedResponse ConnectionFromManagerClient::is_main_mix_muted()
{
return m_mixer.is_muted();
}
void ConnectionFromManagerClient::set_main_mix_muted(bool muted)
{
m_mixer.set_muted(muted);
}
}