summaryrefslogtreecommitdiff
path: root/Servers
diff options
context:
space:
mode:
Diffstat (limited to 'Servers')
-rw-r--r--Servers/AudioServer/ASClientConnection.cpp32
-rw-r--r--Servers/AudioServer/ASClientConnection.h4
-rw-r--r--Servers/AudioServer/ASMixer.h24
-rw-r--r--Servers/AudioServer/AudioServer.ipc5
4 files changed, 62 insertions, 3 deletions
diff --git a/Servers/AudioServer/ASClientConnection.cpp b/Servers/AudioServer/ASClientConnection.cpp
index 43e2e5e813..7bfe1df067 100644
--- a/Servers/AudioServer/ASClientConnection.cpp
+++ b/Servers/AudioServer/ASClientConnection.cpp
@@ -75,8 +75,38 @@ OwnPtr<AudioServer::EnqueueBufferResponse> ASClientConnection::handle(const Audi
OwnPtr<AudioServer::GetRemainingSamplesResponse> ASClientConnection::handle(const AudioServer::GetRemainingSamples&)
{
int remaining = 0;
- if(m_queue)
+ if (m_queue)
remaining = m_queue->get_remaining_samples();
return make<AudioServer::GetRemainingSamplesResponse>(remaining);
}
+
+OwnPtr<AudioServer::GetPlayedSamplesResponse> ASClientConnection::handle(const AudioServer::GetPlayedSamples&)
+{
+ int played = 0;
+ if (m_queue)
+ played = m_queue->get_played_samples();
+
+ return make<AudioServer::GetPlayedSamplesResponse>(played);
+}
+
+OwnPtr<AudioServer::SetPausedResponse> ASClientConnection::handle(const AudioServer::SetPaused& message)
+{
+ if (m_queue)
+ m_queue->set_paused(message.paused());
+ return make<AudioServer::SetPausedResponse>();
+}
+
+OwnPtr<AudioServer::ClearBufferResponse> ASClientConnection::handle(const AudioServer::ClearBuffer& message)
+{
+ if (m_queue)
+ m_queue->clear(message.paused());
+ return make<AudioServer::ClearBufferResponse>();
+}
+
+OwnPtr<AudioServer::GetPlayingBufferResponse> ASClientConnection::handle(const AudioServer::GetPlayingBuffer&){
+ int id = -1;
+ if(m_queue)
+ id = m_queue->get_playing_buffer();
+ return make<AudioServer::GetPlayingBufferResponse>(id);
+}
diff --git a/Servers/AudioServer/ASClientConnection.h b/Servers/AudioServer/ASClientConnection.h
index a50fbd270e..d3946a834f 100644
--- a/Servers/AudioServer/ASClientConnection.h
+++ b/Servers/AudioServer/ASClientConnection.h
@@ -23,6 +23,10 @@ private:
virtual OwnPtr<AudioServer::SetMainMixVolumeResponse> handle(const AudioServer::SetMainMixVolume&) override;
virtual OwnPtr<AudioServer::EnqueueBufferResponse> handle(const AudioServer::EnqueueBuffer&) override;
virtual OwnPtr<AudioServer::GetRemainingSamplesResponse> handle(const AudioServer::GetRemainingSamples&) override;
+ virtual OwnPtr<AudioServer::GetPlayedSamplesResponse> handle(const AudioServer::GetPlayedSamples&) override;
+ virtual OwnPtr<AudioServer::SetPausedResponse> handle(const AudioServer::SetPaused&) override;
+ virtual OwnPtr<AudioServer::ClearBufferResponse> handle(const AudioServer::ClearBuffer&) override;
+ virtual OwnPtr<AudioServer::GetPlayingBufferResponse> handle(const AudioServer::GetPlayingBuffer&) override;
ASMixer& m_mixer;
RefPtr<ASBufferQueue> m_queue;
diff --git a/Servers/AudioServer/ASMixer.h b/Servers/AudioServer/ASMixer.h
index cd086d0da7..e2a823b029 100644
--- a/Servers/AudioServer/ASMixer.h
+++ b/Servers/AudioServer/ASMixer.h
@@ -22,6 +22,9 @@ public:
bool get_next_sample(ASample& sample)
{
+ if (m_paused)
+ return false;
+
while (!m_current && !m_queue.is_empty())
m_current = m_queue.dequeue();
@@ -29,7 +32,8 @@ public:
return false;
sample = m_current->samples()[m_position++];
- m_remaining_samples--;
+ --m_remaining_samples;
+ ++m_played_samples;
if (m_position >= m_current->sample_count()) {
m_current = nullptr;
@@ -40,19 +44,35 @@ public:
ASClientConnection* client() { return m_client.ptr(); }
- void clear()
+ void clear(bool paused = false)
{
m_queue.clear();
m_position = 0;
+ m_remaining_samples = 0;
+ m_played_samples = 0;
+ m_current = nullptr;
+ m_paused = paused;
+ }
+
+ void set_paused(bool paused)
+ {
+ m_paused = paused;
}
int get_remaining_samples() const { return m_remaining_samples; }
+ int get_played_samples() const { return m_played_samples; }
+ int get_playing_buffer() const {
+ if(m_current) return m_current->shared_buffer_id();
+ return -1;
+ }
private:
RefPtr<ABuffer> m_current;
Queue<NonnullRefPtr<ABuffer>> m_queue;
int m_position { 0 };
int m_remaining_samples { 0 };
+ int m_played_samples { 0 };
+ bool m_paused { false };
WeakPtr<ASClientConnection> m_client;
};
diff --git a/Servers/AudioServer/AudioServer.ipc b/Servers/AudioServer/AudioServer.ipc
index a68beef39a..469e226eef 100644
--- a/Servers/AudioServer/AudioServer.ipc
+++ b/Servers/AudioServer/AudioServer.ipc
@@ -9,6 +9,11 @@ endpoint AudioServer
// Buffer playback
EnqueueBuffer(i32 buffer_id, int sample_count) => (bool success)
+ SetPaused(bool paused) => ()
+ ClearBuffer(bool paused) => ()
+ //Buffer information
GetRemainingSamples() => (int remaining_samples)
+ GetPlayedSamples() => (int played_samples)
+ GetPlayingBuffer() => (i32 buffer_id)
}