summaryrefslogtreecommitdiff
path: root/Servers
diff options
context:
space:
mode:
authorTill Mayer <till.mayer@web.de>2019-11-04 19:39:17 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-11-04 20:55:46 +0100
commit2f13517a1adb262dbda8e12cb0aeb7383bf0c812 (patch)
tree28dd6a78b7d4527fefd401a3483d40b642f68cb4 /Servers
parente7ccbdbe306c5295a1bc5ec0d7e7f6f56bb388b0 (diff)
downloadserenity-2f13517a1adb262dbda8e12cb0aeb7383bf0c812.zip
LibAudio: Added playback control features to audio server
LibAudio now supports pausing playback, clearing the buffer queue, retrieving the played samples since the last clear and retrieving the currently playing shared buffer id
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)
}