mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 19:47:34 +00:00
Userland: Rename IPC ClientConnection => ConnectionFromClient
This was done with CLion's automatic rename feature and with: find . -name ClientConnection.h | rename 's/ClientConnection\.h/ConnectionFromClient.h/' find . -name ClientConnection.cpp | rename 's/ClientConnection\.cpp/ConnectionFromClient.cpp/'
This commit is contained in:
parent
efac862570
commit
3a71748e5d
137 changed files with 896 additions and 896 deletions
|
@ -8,7 +8,7 @@ compile_ipc(AudioServer.ipc AudioServerEndpoint.h)
|
|||
compile_ipc(AudioClient.ipc AudioClientEndpoint.h)
|
||||
|
||||
set(SOURCES
|
||||
ClientConnection.cpp
|
||||
ConnectionFromClient.cpp
|
||||
Mixer.cpp
|
||||
main.cpp
|
||||
AudioServerEndpoint.h
|
||||
|
|
|
@ -1,166 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "ClientConnection.h"
|
||||
#include "Mixer.h"
|
||||
#include <AudioServer/AudioClientEndpoint.h>
|
||||
#include <LibAudio/Buffer.h>
|
||||
|
||||
namespace AudioServer {
|
||||
|
||||
static HashMap<int, RefPtr<ClientConnection>> s_connections;
|
||||
|
||||
void ClientConnection::for_each(Function<void(ClientConnection&)> callback)
|
||||
{
|
||||
NonnullRefPtrVector<ClientConnection> connections;
|
||||
for (auto& it : s_connections)
|
||||
connections.append(*it.value);
|
||||
for (auto& connection : connections)
|
||||
callback(connection);
|
||||
}
|
||||
|
||||
ClientConnection::ClientConnection(NonnullOwnPtr<Core::Stream::LocalSocket> client_socket, int client_id, Mixer& mixer)
|
||||
: IPC::ClientConnection<AudioClientEndpoint, AudioServerEndpoint>(*this, move(client_socket), client_id)
|
||||
, m_mixer(mixer)
|
||||
{
|
||||
s_connections.set(client_id, *this);
|
||||
}
|
||||
|
||||
ClientConnection::~ClientConnection()
|
||||
{
|
||||
}
|
||||
|
||||
void ClientConnection::die()
|
||||
{
|
||||
s_connections.remove(client_id());
|
||||
}
|
||||
|
||||
void ClientConnection::did_finish_playing_buffer(Badge<ClientAudioStream>, int buffer_id)
|
||||
{
|
||||
async_finished_playing_buffer(buffer_id);
|
||||
}
|
||||
|
||||
void ClientConnection::did_change_main_mix_muted_state(Badge<Mixer>, bool muted)
|
||||
{
|
||||
async_main_mix_muted_state_changed(muted);
|
||||
}
|
||||
|
||||
void ClientConnection::did_change_main_mix_volume(Badge<Mixer>, double volume)
|
||||
{
|
||||
async_main_mix_volume_changed(volume);
|
||||
}
|
||||
|
||||
void ClientConnection::did_change_client_volume(Badge<ClientAudioStream>, double volume)
|
||||
{
|
||||
async_client_volume_changed(volume);
|
||||
}
|
||||
|
||||
Messages::AudioServer::GetMainMixVolumeResponse ClientConnection::get_main_mix_volume()
|
||||
{
|
||||
return m_mixer.main_volume();
|
||||
}
|
||||
|
||||
void ClientConnection::set_main_mix_volume(double volume)
|
||||
{
|
||||
m_mixer.set_main_volume(volume);
|
||||
}
|
||||
|
||||
Messages::AudioServer::GetSampleRateResponse ClientConnection::get_sample_rate()
|
||||
{
|
||||
return { m_mixer.audiodevice_get_sample_rate() };
|
||||
}
|
||||
|
||||
void ClientConnection::set_sample_rate(u32 sample_rate)
|
||||
{
|
||||
m_mixer.audiodevice_set_sample_rate(sample_rate);
|
||||
}
|
||||
|
||||
Messages::AudioServer::GetSelfVolumeResponse ClientConnection::get_self_volume()
|
||||
{
|
||||
return m_queue->volume().target();
|
||||
}
|
||||
|
||||
void ClientConnection::set_self_volume(double volume)
|
||||
{
|
||||
if (m_queue)
|
||||
m_queue->set_volume(volume);
|
||||
}
|
||||
|
||||
Messages::AudioServer::EnqueueBufferResponse ClientConnection::enqueue_buffer(Core::AnonymousBuffer const& buffer, i32 buffer_id, int sample_count)
|
||||
{
|
||||
if (!m_queue)
|
||||
m_queue = m_mixer.create_queue(*this);
|
||||
|
||||
if (m_queue->is_full())
|
||||
return false;
|
||||
|
||||
// There's not a big allocation to worry about here.
|
||||
m_queue->enqueue(MUST(Audio::Buffer::create_with_anonymous_buffer(buffer, buffer_id, sample_count)));
|
||||
return true;
|
||||
}
|
||||
|
||||
Messages::AudioServer::GetRemainingSamplesResponse ClientConnection::get_remaining_samples()
|
||||
{
|
||||
int remaining = 0;
|
||||
if (m_queue)
|
||||
remaining = m_queue->get_remaining_samples();
|
||||
|
||||
return remaining;
|
||||
}
|
||||
|
||||
Messages::AudioServer::GetPlayedSamplesResponse ClientConnection::get_played_samples()
|
||||
{
|
||||
int played = 0;
|
||||
if (m_queue)
|
||||
played = m_queue->get_played_samples();
|
||||
|
||||
return played;
|
||||
}
|
||||
|
||||
void ClientConnection::set_paused(bool paused)
|
||||
{
|
||||
if (m_queue)
|
||||
m_queue->set_paused(paused);
|
||||
}
|
||||
|
||||
void ClientConnection::clear_buffer(bool paused)
|
||||
{
|
||||
if (m_queue)
|
||||
m_queue->clear(paused);
|
||||
}
|
||||
|
||||
Messages::AudioServer::GetPlayingBufferResponse ClientConnection::get_playing_buffer()
|
||||
{
|
||||
int id = -1;
|
||||
if (m_queue)
|
||||
id = m_queue->get_playing_buffer();
|
||||
return id;
|
||||
}
|
||||
|
||||
Messages::AudioServer::IsMainMixMutedResponse ClientConnection::is_main_mix_muted()
|
||||
{
|
||||
return m_mixer.is_muted();
|
||||
}
|
||||
|
||||
void ClientConnection::set_main_mix_muted(bool muted)
|
||||
{
|
||||
m_mixer.set_muted(muted);
|
||||
}
|
||||
|
||||
Messages::AudioServer::IsSelfMutedResponse ClientConnection::is_self_muted()
|
||||
{
|
||||
if (m_queue)
|
||||
return m_queue->is_muted();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ClientConnection::set_self_muted(bool muted)
|
||||
{
|
||||
if (m_queue)
|
||||
m_queue->set_muted(muted);
|
||||
}
|
||||
}
|
166
Userland/Services/AudioServer/ConnectionFromClient.cpp
Normal file
166
Userland/Services/AudioServer/ConnectionFromClient.cpp
Normal file
|
@ -0,0 +1,166 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "ConnectionFromClient.h"
|
||||
#include "Mixer.h"
|
||||
#include <AudioServer/AudioClientEndpoint.h>
|
||||
#include <LibAudio/Buffer.h>
|
||||
|
||||
namespace AudioServer {
|
||||
|
||||
static HashMap<int, RefPtr<ConnectionFromClient>> s_connections;
|
||||
|
||||
void ConnectionFromClient::for_each(Function<void(ConnectionFromClient&)> callback)
|
||||
{
|
||||
NonnullRefPtrVector<ConnectionFromClient> connections;
|
||||
for (auto& it : s_connections)
|
||||
connections.append(*it.value);
|
||||
for (auto& connection : connections)
|
||||
callback(connection);
|
||||
}
|
||||
|
||||
ConnectionFromClient::ConnectionFromClient(NonnullOwnPtr<Core::Stream::LocalSocket> client_socket, int client_id, Mixer& mixer)
|
||||
: IPC::ConnectionFromClient<AudioClientEndpoint, AudioServerEndpoint>(*this, move(client_socket), client_id)
|
||||
, m_mixer(mixer)
|
||||
{
|
||||
s_connections.set(client_id, *this);
|
||||
}
|
||||
|
||||
ConnectionFromClient::~ConnectionFromClient()
|
||||
{
|
||||
}
|
||||
|
||||
void ConnectionFromClient::die()
|
||||
{
|
||||
s_connections.remove(client_id());
|
||||
}
|
||||
|
||||
void ConnectionFromClient::did_finish_playing_buffer(Badge<ClientAudioStream>, int buffer_id)
|
||||
{
|
||||
async_finished_playing_buffer(buffer_id);
|
||||
}
|
||||
|
||||
void ConnectionFromClient::did_change_main_mix_muted_state(Badge<Mixer>, bool muted)
|
||||
{
|
||||
async_main_mix_muted_state_changed(muted);
|
||||
}
|
||||
|
||||
void ConnectionFromClient::did_change_main_mix_volume(Badge<Mixer>, double volume)
|
||||
{
|
||||
async_main_mix_volume_changed(volume);
|
||||
}
|
||||
|
||||
void ConnectionFromClient::did_change_client_volume(Badge<ClientAudioStream>, double volume)
|
||||
{
|
||||
async_client_volume_changed(volume);
|
||||
}
|
||||
|
||||
Messages::AudioServer::GetMainMixVolumeResponse ConnectionFromClient::get_main_mix_volume()
|
||||
{
|
||||
return m_mixer.main_volume();
|
||||
}
|
||||
|
||||
void ConnectionFromClient::set_main_mix_volume(double volume)
|
||||
{
|
||||
m_mixer.set_main_volume(volume);
|
||||
}
|
||||
|
||||
Messages::AudioServer::GetSampleRateResponse ConnectionFromClient::get_sample_rate()
|
||||
{
|
||||
return { m_mixer.audiodevice_get_sample_rate() };
|
||||
}
|
||||
|
||||
void ConnectionFromClient::set_sample_rate(u32 sample_rate)
|
||||
{
|
||||
m_mixer.audiodevice_set_sample_rate(sample_rate);
|
||||
}
|
||||
|
||||
Messages::AudioServer::GetSelfVolumeResponse ConnectionFromClient::get_self_volume()
|
||||
{
|
||||
return m_queue->volume().target();
|
||||
}
|
||||
|
||||
void ConnectionFromClient::set_self_volume(double volume)
|
||||
{
|
||||
if (m_queue)
|
||||
m_queue->set_volume(volume);
|
||||
}
|
||||
|
||||
Messages::AudioServer::EnqueueBufferResponse ConnectionFromClient::enqueue_buffer(Core::AnonymousBuffer const& buffer, i32 buffer_id, int sample_count)
|
||||
{
|
||||
if (!m_queue)
|
||||
m_queue = m_mixer.create_queue(*this);
|
||||
|
||||
if (m_queue->is_full())
|
||||
return false;
|
||||
|
||||
// There's not a big allocation to worry about here.
|
||||
m_queue->enqueue(MUST(Audio::Buffer::create_with_anonymous_buffer(buffer, buffer_id, sample_count)));
|
||||
return true;
|
||||
}
|
||||
|
||||
Messages::AudioServer::GetRemainingSamplesResponse ConnectionFromClient::get_remaining_samples()
|
||||
{
|
||||
int remaining = 0;
|
||||
if (m_queue)
|
||||
remaining = m_queue->get_remaining_samples();
|
||||
|
||||
return remaining;
|
||||
}
|
||||
|
||||
Messages::AudioServer::GetPlayedSamplesResponse ConnectionFromClient::get_played_samples()
|
||||
{
|
||||
int played = 0;
|
||||
if (m_queue)
|
||||
played = m_queue->get_played_samples();
|
||||
|
||||
return played;
|
||||
}
|
||||
|
||||
void ConnectionFromClient::set_paused(bool paused)
|
||||
{
|
||||
if (m_queue)
|
||||
m_queue->set_paused(paused);
|
||||
}
|
||||
|
||||
void ConnectionFromClient::clear_buffer(bool paused)
|
||||
{
|
||||
if (m_queue)
|
||||
m_queue->clear(paused);
|
||||
}
|
||||
|
||||
Messages::AudioServer::GetPlayingBufferResponse ConnectionFromClient::get_playing_buffer()
|
||||
{
|
||||
int id = -1;
|
||||
if (m_queue)
|
||||
id = m_queue->get_playing_buffer();
|
||||
return id;
|
||||
}
|
||||
|
||||
Messages::AudioServer::IsMainMixMutedResponse ConnectionFromClient::is_main_mix_muted()
|
||||
{
|
||||
return m_mixer.is_muted();
|
||||
}
|
||||
|
||||
void ConnectionFromClient::set_main_mix_muted(bool muted)
|
||||
{
|
||||
m_mixer.set_muted(muted);
|
||||
}
|
||||
|
||||
Messages::AudioServer::IsSelfMutedResponse ConnectionFromClient::is_self_muted()
|
||||
{
|
||||
if (m_queue)
|
||||
return m_queue->is_muted();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ConnectionFromClient::set_self_muted(bool muted)
|
||||
{
|
||||
if (m_queue)
|
||||
m_queue->set_muted(muted);
|
||||
}
|
||||
}
|
|
@ -9,7 +9,7 @@
|
|||
#include <AK/HashMap.h>
|
||||
#include <AudioServer/AudioClientEndpoint.h>
|
||||
#include <AudioServer/AudioServerEndpoint.h>
|
||||
#include <LibIPC/ClientConnection.h>
|
||||
#include <LibIPC/ConnectionFromClient.h>
|
||||
|
||||
namespace Audio {
|
||||
class Buffer;
|
||||
|
@ -20,10 +20,10 @@ namespace AudioServer {
|
|||
class ClientAudioStream;
|
||||
class Mixer;
|
||||
|
||||
class ClientConnection final : public IPC::ClientConnection<AudioClientEndpoint, AudioServerEndpoint> {
|
||||
C_OBJECT(ClientConnection)
|
||||
class ConnectionFromClient final : public IPC::ConnectionFromClient<AudioClientEndpoint, AudioServerEndpoint> {
|
||||
C_OBJECT(ConnectionFromClient)
|
||||
public:
|
||||
~ClientConnection() override;
|
||||
~ConnectionFromClient() override;
|
||||
|
||||
void did_finish_playing_buffer(Badge<ClientAudioStream>, int buffer_id);
|
||||
void did_change_client_volume(Badge<ClientAudioStream>, double volume);
|
||||
|
@ -32,10 +32,10 @@ public:
|
|||
|
||||
virtual void die() override;
|
||||
|
||||
static void for_each(Function<void(ClientConnection&)>);
|
||||
static void for_each(Function<void(ConnectionFromClient&)>);
|
||||
|
||||
private:
|
||||
explicit ClientConnection(NonnullOwnPtr<Core::Stream::LocalSocket>, int client_id, Mixer& mixer);
|
||||
explicit ConnectionFromClient(NonnullOwnPtr<Core::Stream::LocalSocket>, int client_id, Mixer& mixer);
|
||||
|
||||
virtual Messages::AudioServer::GetMainMixVolumeResponse get_main_mix_volume() override;
|
||||
virtual void set_main_mix_volume(double) override;
|
|
@ -10,7 +10,7 @@
|
|||
#include <AK/Array.h>
|
||||
#include <AK/MemoryStream.h>
|
||||
#include <AK/NumericLimits.h>
|
||||
#include <AudioServer/ClientConnection.h>
|
||||
#include <AudioServer/ConnectionFromClient.h>
|
||||
#include <AudioServer/Mixer.h>
|
||||
#include <LibCore/ConfigFile.h>
|
||||
#include <LibCore/Timer.h>
|
||||
|
@ -48,7 +48,7 @@ Mixer::~Mixer()
|
|||
{
|
||||
}
|
||||
|
||||
NonnullRefPtr<ClientAudioStream> Mixer::create_queue(ClientConnection& client)
|
||||
NonnullRefPtr<ClientAudioStream> Mixer::create_queue(ConnectionFromClient& client)
|
||||
{
|
||||
auto queue = adopt_ref(*new ClientAudioStream(client));
|
||||
m_pending_mutex.lock();
|
||||
|
@ -149,7 +149,7 @@ void Mixer::set_main_volume(double volume)
|
|||
m_config->write_num_entry("Master", "Volume", static_cast<int>(volume * 100));
|
||||
request_setting_sync();
|
||||
|
||||
ClientConnection::for_each([&](ClientConnection& client) {
|
||||
ConnectionFromClient::for_each([&](ConnectionFromClient& client) {
|
||||
client.did_change_main_mix_volume({}, main_volume());
|
||||
});
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ void Mixer::set_muted(bool muted)
|
|||
m_config->write_bool_entry("Master", "Mute", m_muted);
|
||||
request_setting_sync();
|
||||
|
||||
ClientConnection::for_each([muted](ClientConnection& client) {
|
||||
ConnectionFromClient::for_each([muted](ConnectionFromClient& client) {
|
||||
client.did_change_main_mix_muted_state({}, muted);
|
||||
});
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ void Mixer::request_setting_sync()
|
|||
}
|
||||
}
|
||||
|
||||
ClientAudioStream::ClientAudioStream(ClientConnection& client)
|
||||
ClientAudioStream::ClientAudioStream(ConnectionFromClient& client)
|
||||
: m_client(client)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "ClientConnection.h"
|
||||
#include "ConnectionFromClient.h"
|
||||
#include "FadingProperty.h"
|
||||
#include <AK/Atomic.h>
|
||||
#include <AK/Badge.h>
|
||||
|
@ -30,11 +30,11 @@ namespace AudioServer {
|
|||
// This is to prevent clipping when two streams with low headroom (e.g. normalized & compressed) are playing.
|
||||
constexpr double SAMPLE_HEADROOM = 0.7;
|
||||
|
||||
class ClientConnection;
|
||||
class ConnectionFromClient;
|
||||
|
||||
class ClientAudioStream : public RefCounted<ClientAudioStream> {
|
||||
public:
|
||||
explicit ClientAudioStream(ClientConnection&);
|
||||
explicit ClientAudioStream(ConnectionFromClient&);
|
||||
~ClientAudioStream() { }
|
||||
|
||||
bool is_full() const { return m_queue.size() >= 3; }
|
||||
|
@ -64,7 +64,7 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
ClientConnection* client() { return m_client.ptr(); }
|
||||
ConnectionFromClient* client() { return m_client.ptr(); }
|
||||
|
||||
void clear(bool paused = false)
|
||||
{
|
||||
|
@ -105,7 +105,7 @@ private:
|
|||
bool m_paused { false };
|
||||
bool m_muted { false };
|
||||
|
||||
WeakPtr<ClientConnection> m_client;
|
||||
WeakPtr<ConnectionFromClient> m_client;
|
||||
FadingProperty<double> m_volume { 1 };
|
||||
};
|
||||
|
||||
|
@ -114,7 +114,7 @@ class Mixer : public Core::Object {
|
|||
public:
|
||||
virtual ~Mixer() override;
|
||||
|
||||
NonnullRefPtr<ClientAudioStream> create_queue(ClientConnection&);
|
||||
NonnullRefPtr<ClientAudioStream> create_queue(ConnectionFromClient&);
|
||||
|
||||
// To the outside world, we pretend that the target volume is already reached, even though it may be still fading.
|
||||
double main_volume() const { return m_main_volume.target(); }
|
||||
|
|
|
@ -28,7 +28,7 @@ ErrorOr<int> serenity_main(Main::Arguments)
|
|||
server->on_accept = [&](NonnullOwnPtr<Core::Stream::LocalSocket> client_socket) {
|
||||
static int s_next_client_id = 0;
|
||||
int client_id = ++s_next_client_id;
|
||||
(void)IPC::new_client_connection<AudioServer::ClientConnection>(move(client_socket), client_id, *mixer);
|
||||
(void)IPC::new_client_connection<AudioServer::ConnectionFromClient>(move(client_socket), client_id, *mixer);
|
||||
};
|
||||
|
||||
TRY(Core::System::pledge("stdio recvfd thread accept cpath rpath wpath"));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue