summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsppmacd <sppmacd@gmail.com>2020-06-12 17:00:03 +0200
committerAndreas Kling <kling@serenityos.org>2020-06-12 20:42:22 +0200
commit15f4043a7a80f52c0fa05c4e69771e758464cd20 (patch)
tree0bbd5717236cbd49f094223bc5951f6e17e21ac6
parentc91981eba825155521dfeadc9aec3961d3590b23 (diff)
downloadserenity-15f4043a7a80f52c0fa05c4e69771e758464cd20.zip
AudioServer: removed AS prefix from class and file names
And moved everything to AudioServer namespace
-rw-r--r--Services/AudioServer/CMakeLists.txt4
-rw-r--r--Services/AudioServer/ClientConnection.cpp (renamed from Services/AudioServer/ASClientConnection.cpp)45
-rw-r--r--Services/AudioServer/ClientConnection.h (renamed from Services/AudioServer/ASClientConnection.h)26
-rw-r--r--Services/AudioServer/Mixer.cpp (renamed from Services/AudioServer/ASMixer.cpp)25
-rw-r--r--Services/AudioServer/Mixer.h (renamed from Services/AudioServer/ASMixer.h)43
-rw-r--r--Services/AudioServer/main.cpp6
6 files changed, 81 insertions, 68 deletions
diff --git a/Services/AudioServer/CMakeLists.txt b/Services/AudioServer/CMakeLists.txt
index 4ae91fb090..9c71197b62 100644
--- a/Services/AudioServer/CMakeLists.txt
+++ b/Services/AudioServer/CMakeLists.txt
@@ -2,8 +2,8 @@ compile_ipc(AudioServer.ipc AudioServerEndpoint.h)
compile_ipc(AudioClient.ipc AudioClientEndpoint.h)
set(SOURCES
- ASClientConnection.cpp
- ASMixer.cpp
+ ClientConnection.cpp
+ Mixer.cpp
main.cpp
AudioServerEndpoint.h
AudioClientEndpoint.h
diff --git a/Services/AudioServer/ASClientConnection.cpp b/Services/AudioServer/ClientConnection.cpp
index c941ffcf2a..a7d5a3d540 100644
--- a/Services/AudioServer/ASClientConnection.cpp
+++ b/Services/AudioServer/ClientConnection.cpp
@@ -24,8 +24,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "ASClientConnection.h"
-#include "ASMixer.h"
+#include "ClientConnection.h"
+#include "Mixer.h"
#include <AK/SharedBuffer.h>
#include <AudioServer/AudioClientEndpoint.h>
#include <LibAudio/Buffer.h>
@@ -37,60 +37,62 @@
#include <sys/uio.h>
#include <unistd.h>
-static HashMap<int, RefPtr<ASClientConnection>> s_connections;
+namespace AudioServer {
-void ASClientConnection::for_each(Function<void(ASClientConnection&)> callback)
+static HashMap<int, RefPtr<ClientConnection>> s_connections;
+
+void ClientConnection::for_each(Function<void(ClientConnection&)> callback)
{
- NonnullRefPtrVector<ASClientConnection> connections;
+ NonnullRefPtrVector<ClientConnection> connections;
for (auto& it : s_connections)
connections.append(*it.value);
for (auto& connection : connections)
callback(connection);
}
-ASClientConnection::ASClientConnection(Core::LocalSocket& client_socket, int client_id, ASMixer& mixer)
+ClientConnection::ClientConnection(Core::LocalSocket& client_socket, int client_id, Mixer& mixer)
: IPC::ClientConnection<AudioServerEndpoint>(*this, client_socket, client_id)
, m_mixer(mixer)
{
s_connections.set(client_id, *this);
}
-ASClientConnection::~ASClientConnection()
+ClientConnection::~ClientConnection()
{
}
-void ASClientConnection::die()
+void ClientConnection::die()
{
s_connections.remove(client_id());
}
-void ASClientConnection::did_finish_playing_buffer(Badge<ASBufferQueue>, int buffer_id)
+void ClientConnection::did_finish_playing_buffer(Badge<BufferQueue>, int buffer_id)
{
post_message(Messages::AudioClient::FinishedPlayingBuffer(buffer_id));
}
-void ASClientConnection::did_change_muted_state(Badge<ASMixer>, bool muted)
+void ClientConnection::did_change_muted_state(Badge<Mixer>, bool muted)
{
post_message(Messages::AudioClient::MutedStateChanged(muted));
}
-OwnPtr<Messages::AudioServer::GreetResponse> ASClientConnection::handle(const Messages::AudioServer::Greet&)
+OwnPtr<Messages::AudioServer::GreetResponse> ClientConnection::handle(const Messages::AudioServer::Greet&)
{
return make<Messages::AudioServer::GreetResponse>(client_id());
}
-OwnPtr<Messages::AudioServer::GetMainMixVolumeResponse> ASClientConnection::handle(const Messages::AudioServer::GetMainMixVolume&)
+OwnPtr<Messages::AudioServer::GetMainMixVolumeResponse> ClientConnection::handle(const Messages::AudioServer::GetMainMixVolume&)
{
return make<Messages::AudioServer::GetMainMixVolumeResponse>(m_mixer.main_volume());
}
-OwnPtr<Messages::AudioServer::SetMainMixVolumeResponse> ASClientConnection::handle(const Messages::AudioServer::SetMainMixVolume& message)
+OwnPtr<Messages::AudioServer::SetMainMixVolumeResponse> ClientConnection::handle(const Messages::AudioServer::SetMainMixVolume& message)
{
m_mixer.set_main_volume(message.volume());
return make<Messages::AudioServer::SetMainMixVolumeResponse>();
}
-OwnPtr<Messages::AudioServer::EnqueueBufferResponse> ASClientConnection::handle(const Messages::AudioServer::EnqueueBuffer& message)
+OwnPtr<Messages::AudioServer::EnqueueBufferResponse> ClientConnection::handle(const Messages::AudioServer::EnqueueBuffer& message)
{
auto shared_buffer = SharedBuffer::create_from_shbuf_id(message.buffer_id());
if (!shared_buffer) {
@@ -109,7 +111,7 @@ OwnPtr<Messages::AudioServer::EnqueueBufferResponse> ASClientConnection::handle(
return make<Messages::AudioServer::EnqueueBufferResponse>(true);
}
-OwnPtr<Messages::AudioServer::GetRemainingSamplesResponse> ASClientConnection::handle(const Messages::AudioServer::GetRemainingSamples&)
+OwnPtr<Messages::AudioServer::GetRemainingSamplesResponse> ClientConnection::handle(const Messages::AudioServer::GetRemainingSamples&)
{
int remaining = 0;
if (m_queue)
@@ -118,7 +120,7 @@ OwnPtr<Messages::AudioServer::GetRemainingSamplesResponse> ASClientConnection::h
return make<Messages::AudioServer::GetRemainingSamplesResponse>(remaining);
}
-OwnPtr<Messages::AudioServer::GetPlayedSamplesResponse> ASClientConnection::handle(const Messages::AudioServer::GetPlayedSamples&)
+OwnPtr<Messages::AudioServer::GetPlayedSamplesResponse> ClientConnection::handle(const Messages::AudioServer::GetPlayedSamples&)
{
int played = 0;
if (m_queue)
@@ -127,21 +129,21 @@ OwnPtr<Messages::AudioServer::GetPlayedSamplesResponse> ASClientConnection::hand
return make<Messages::AudioServer::GetPlayedSamplesResponse>(played);
}
-OwnPtr<Messages::AudioServer::SetPausedResponse> ASClientConnection::handle(const Messages::AudioServer::SetPaused& message)
+OwnPtr<Messages::AudioServer::SetPausedResponse> ClientConnection::handle(const Messages::AudioServer::SetPaused& message)
{
if (m_queue)
m_queue->set_paused(message.paused());
return make<Messages::AudioServer::SetPausedResponse>();
}
-OwnPtr<Messages::AudioServer::ClearBufferResponse> ASClientConnection::handle(const Messages::AudioServer::ClearBuffer& message)
+OwnPtr<Messages::AudioServer::ClearBufferResponse> ClientConnection::handle(const Messages::AudioServer::ClearBuffer& message)
{
if (m_queue)
m_queue->clear(message.paused());
return make<Messages::AudioServer::ClearBufferResponse>();
}
-OwnPtr<Messages::AudioServer::GetPlayingBufferResponse> ASClientConnection::handle(const Messages::AudioServer::GetPlayingBuffer&)
+OwnPtr<Messages::AudioServer::GetPlayingBufferResponse> ClientConnection::handle(const Messages::AudioServer::GetPlayingBuffer&)
{
int id = -1;
if (m_queue)
@@ -149,13 +151,14 @@ OwnPtr<Messages::AudioServer::GetPlayingBufferResponse> ASClientConnection::hand
return make<Messages::AudioServer::GetPlayingBufferResponse>(id);
}
-OwnPtr<Messages::AudioServer::GetMutedResponse> ASClientConnection::handle(const Messages::AudioServer::GetMuted&)
+OwnPtr<Messages::AudioServer::GetMutedResponse> ClientConnection::handle(const Messages::AudioServer::GetMuted&)
{
return make<Messages::AudioServer::GetMutedResponse>(m_mixer.is_muted());
}
-OwnPtr<Messages::AudioServer::SetMutedResponse> ASClientConnection::handle(const Messages::AudioServer::SetMuted& message)
+OwnPtr<Messages::AudioServer::SetMutedResponse> ClientConnection::handle(const Messages::AudioServer::SetMuted& message)
{
m_mixer.set_muted(message.muted());
return make<Messages::AudioServer::SetMutedResponse>();
}
+}
diff --git a/Services/AudioServer/ASClientConnection.h b/Services/AudioServer/ClientConnection.h
index c76c51eb36..2befe48ab8 100644
--- a/Services/AudioServer/ASClientConnection.h
+++ b/Services/AudioServer/ClientConnection.h
@@ -34,22 +34,24 @@ namespace Audio {
class Buffer;
}
-class ASBufferQueue;
-class ASMixer;
+namespace AudioServer {
-class ASClientConnection final : public IPC::ClientConnection<AudioServerEndpoint>
+class BufferQueue;
+class Mixer;
+
+class ClientConnection final : public IPC::ClientConnection<AudioServerEndpoint>
, public AudioServerEndpoint {
- C_OBJECT(ASClientConnection)
+ C_OBJECT(ClientConnection)
public:
- explicit ASClientConnection(Core::LocalSocket&, int client_id, ASMixer& mixer);
- ~ASClientConnection() override;
+ explicit ClientConnection(Core::LocalSocket&, int client_id, Mixer& mixer);
+ ~ClientConnection() override;
- void did_finish_playing_buffer(Badge<ASBufferQueue>, int buffer_id);
- void did_change_muted_state(Badge<ASMixer>, bool muted);
+ void did_finish_playing_buffer(Badge<BufferQueue>, int buffer_id);
+ void did_change_muted_state(Badge<Mixer>, bool muted);
virtual void die() override;
- static void for_each(Function<void(ASClientConnection&)>);
+ static void for_each(Function<void(ClientConnection&)>);
private:
virtual OwnPtr<Messages::AudioServer::GreetResponse> handle(const Messages::AudioServer::Greet&) override;
@@ -64,6 +66,8 @@ private:
virtual OwnPtr<Messages::AudioServer::GetMutedResponse> handle(const Messages::AudioServer::GetMuted&) override;
virtual OwnPtr<Messages::AudioServer::SetMutedResponse> handle(const Messages::AudioServer::SetMuted&) override;
- ASMixer& m_mixer;
- RefPtr<ASBufferQueue> m_queue;
+ Mixer& m_mixer;
+ RefPtr<BufferQueue> m_queue;
};
+
+}
diff --git a/Services/AudioServer/ASMixer.cpp b/Services/AudioServer/Mixer.cpp
index 3d9ff00cc5..20daa529cf 100644
--- a/Services/AudioServer/ASMixer.cpp
+++ b/Services/AudioServer/Mixer.cpp
@@ -26,11 +26,13 @@
#include <AK/BufferStream.h>
#include <AK/NumericLimits.h>
-#include <AudioServer/ASClientConnection.h>
-#include <AudioServer/ASMixer.h>
+#include <AudioServer/ClientConnection.h>
+#include <AudioServer/Mixer.h>
#include <pthread.h>
-ASMixer::ASMixer()
+namespace AudioServer {
+
+Mixer::Mixer()
: m_device(Core::File::construct("/dev/audio", this))
, m_sound_thread(
[this] {
@@ -52,13 +54,13 @@ ASMixer::ASMixer()
m_sound_thread.start();
}
-ASMixer::~ASMixer()
+Mixer::~Mixer()
{
}
-NonnullRefPtr<ASBufferQueue> ASMixer::create_queue(ASClientConnection& client)
+NonnullRefPtr<BufferQueue> Mixer::create_queue(ClientConnection& client)
{
- auto queue = adopt(*new ASBufferQueue(client));
+ auto queue = adopt(*new BufferQueue(client));
pthread_mutex_lock(&m_pending_mutex);
m_pending_mixing.append(*queue);
pthread_cond_signal(&m_pending_cond);
@@ -66,7 +68,7 @@ NonnullRefPtr<ASBufferQueue> ASMixer::create_queue(ASClientConnection& client)
return queue;
}
-void ASMixer::mix()
+void Mixer::mix()
{
decltype(m_pending_mixing) active_mix_queues;
@@ -130,23 +132,24 @@ void ASMixer::mix()
}
}
-void ASMixer::set_muted(bool muted)
+void Mixer::set_muted(bool muted)
{
if (m_muted == muted)
return;
m_muted = muted;
- ASClientConnection::for_each([muted](ASClientConnection& client) {
+ ClientConnection::for_each([muted](ClientConnection& client) {
client.did_change_muted_state({}, muted);
});
}
-ASBufferQueue::ASBufferQueue(ASClientConnection& client)
+BufferQueue::BufferQueue(ClientConnection& client)
: m_client(client.make_weak_ptr())
{
}
-void ASBufferQueue::enqueue(NonnullRefPtr<Audio::Buffer>&& buffer)
+void BufferQueue::enqueue(NonnullRefPtr<Audio::Buffer>&& buffer)
{
m_remaining_samples += buffer->sample_count();
m_queue.enqueue(move(buffer));
}
+}
diff --git a/Services/AudioServer/ASMixer.h b/Services/AudioServer/Mixer.h
index e5ed5874b2..bdfc4c8928 100644
--- a/Services/AudioServer/ASMixer.h
+++ b/Services/AudioServer/Mixer.h
@@ -26,7 +26,7 @@
#pragma once
-#include "ASClientConnection.h"
+#include "ClientConnection.h"
#include <AK/Badge.h>
#include <AK/ByteBuffer.h>
#include <AK/NonnullRefPtrVector.h>
@@ -38,12 +38,14 @@
#include <LibThread/Lock.h>
#include <LibThread/Thread.h>
-class ASClientConnection;
+namespace AudioServer {
-class ASBufferQueue : public RefCounted<ASBufferQueue> {
+class ClientConnection;
+
+class BufferQueue : public RefCounted<BufferQueue> {
public:
- explicit ASBufferQueue(ASClientConnection&);
- ~ASBufferQueue() {}
+ explicit BufferQueue(ClientConnection&);
+ ~BufferQueue() {}
bool is_full() const { return m_queue.size() >= 3; }
void enqueue(NonnullRefPtr<Audio::Buffer>&&);
@@ -71,7 +73,7 @@ public:
return true;
}
- ASClientConnection* client() { return m_client.ptr(); }
+ ClientConnection* client() { return m_client.ptr(); }
void clear(bool paused = false)
{
@@ -100,20 +102,20 @@ public:
private:
RefPtr<Audio::Buffer> m_current;
Queue<NonnullRefPtr<Audio::Buffer>> m_queue;
- int m_position { 0 };
- int m_remaining_samples { 0 };
- int m_played_samples { 0 };
- bool m_paused { false };
- WeakPtr<ASClientConnection> m_client;
+ int m_position{ 0 };
+ int m_remaining_samples{ 0 };
+ int m_played_samples{ 0 };
+ bool m_paused{ false };
+ WeakPtr<ClientConnection> m_client;
};
-class ASMixer : public Core::Object {
- C_OBJECT(ASMixer)
+class Mixer : public Core::Object {
+ C_OBJECT(Mixer)
public:
- ASMixer();
- virtual ~ASMixer() override;
+ Mixer();
+ virtual ~Mixer() override;
- NonnullRefPtr<ASBufferQueue> create_queue(ASClientConnection&);
+ NonnullRefPtr<BufferQueue> create_queue(ClientConnection&);
int main_volume() const { return m_main_volume; }
void set_main_volume(int volume) { m_main_volume = volume; }
@@ -122,7 +124,7 @@ public:
void set_muted(bool);
private:
- Vector<NonnullRefPtr<ASBufferQueue>> m_pending_mixing;
+ Vector<NonnullRefPtr<BufferQueue>> m_pending_mixing;
pthread_mutex_t m_pending_mutex;
pthread_cond_t m_pending_cond;
@@ -130,10 +132,11 @@ private:
LibThread::Thread m_sound_thread;
- bool m_muted { false };
- int m_main_volume { 100 };
+ bool m_muted{ false };
+ int m_main_volume{ 100 };
- u8* m_zero_filled_buffer { nullptr };
+ u8* m_zero_filled_buffer{ nullptr };
void mix();
};
+}
diff --git a/Services/AudioServer/main.cpp b/Services/AudioServer/main.cpp
index 5907dd77c6..6f960396cc 100644
--- a/Services/AudioServer/main.cpp
+++ b/Services/AudioServer/main.cpp
@@ -24,7 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "ASMixer.h"
+#include "Mixer.h"
#include <LibCore/File.h>
#include <LibCore/LocalServer.h>
@@ -36,7 +36,7 @@ int main(int, char**)
}
Core::EventLoop event_loop;
- ASMixer mixer;
+ AudioServer::Mixer mixer;
auto server = Core::LocalServer::construct();
bool ok = server->take_over_from_system_server();
@@ -49,7 +49,7 @@ int main(int, char**)
}
static int s_next_client_id = 0;
int client_id = ++s_next_client_id;
- IPC::new_client_connection<ASClientConnection>(*client_socket, client_id, mixer);
+ IPC::new_client_connection<AudioServer::ClientConnection>(*client_socket, client_id, mixer);
};
if (pledge("stdio thread shared_buffer accept", nullptr) < 0) {